Re: Help please: Trouble getting a value back from COM.
Roger I Martin PhD <[email protected]>
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <[email protected]> |
Are you writing both sides? primitives such as int and float can go across as int[] on the Java side and int* on the COM side. Creation of objects on the COM and passed back up thru the argument list may not be supported. (Recognise that I didn't write the original marshaling; am talking with others about giving it a refactoring). If you are writing both side you can make the Java side have a String of the correct size and fill it in. Some Variants are working but anything with dynamic data has this same problem. (The longated marshalling byte array does not seem to allow for chunks to get larger or smaller (could be very inefficient). The marshaling takes everything out of pointers and lays their data end to end. I don't see anything growing and shrinking this array in the code. IMO needs a rewrite. Also there are new native io and JNI functionality to take advantage of in 1.5. May leap over 1.4 or have what can work with 1.4. ----- Original Message ----- From: "Darrin Smith" <[email protected]> To: <[email protected]> Sent: Friday, June 04, 2004 12:10 PM Subject: [JAWIN] Help please: Trouble getting a value back from COM. > How do you need to set up the COM side to be able to get a value back to > your Jawin application without using simple getXXX methods? In other words, > I'd like to have a method that returns a value based on a parameter I send. > > For example, I have a DLL that had a method that looks like this: > > STDMETHODIMP CValidateLogin::Garbage(BSTR InputString, int InputInt, BSTR > returnString) > { > returnString = CString(_T("blah")).AllocSysString(); > return 0; > } > > I can call this just fine, but of course I can't get the value back out > (call by value on the returnString), so I modified the Garbage method to > take an array. It ended up looking like this: > > STDMETHODIMP CValidateLogin::Garbage(BSTR InputString, int InputInt,BSTR > returnString[1]) > { > returnString[0] = CString(_T("blah")).AllocSysString(); > return 0; > } > > This compiled just fine after changing the IDL and header file, but when I > ran it through the Jawin Type Browser, it would hang (out of memory I > think...even after I upped it to 256meg). > > Next, I and a coworker (COM guy) tried to use a VARIANT like this: > > STDMETHODIMP CValidateLogin::Garbage(BSTR InputString, int > InputInt,VARIANT* returnString) > { > returnString->bstrVal = CString(_T("blah")).AllocSysString(); > return 0; > } > > When that is run through the Jawin Type Browser, it ends up with this: > > public void Garbage(String InputString,int InputInt,Variant[] returnString) > throws COMException > { > invokeN("Garbage", new Object[] {InputString, new Integer(InputInt), > returnString}); > } > > This is just fine, but when I run this: > > Variant[] v = new Variant[5]; > > iLogin.Garbage("InputString", 5, v); > > it gives me this error: > > An unexpected exception has been detected in native code outside the VM. > Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at > PC=0x7715CB4D > Function=SafeArrayAllocDescriptor+0xA0 > Library=C:\WINDOWS\system32\OLEAUT32.dll > Current Java thread: > at org.jawin.marshal.GenericStub.dispatchInvoke0(Native Method) > at org.jawin.marshal.GenericStub.dispatchInvoke(GenericStub.java:84) > at org.jawin.DispatchPtr.invokeN(DispatchPtr.java:473) > at org.jawin.DispatchPtr.invokeN(DispatchPtr.java:433) > ... > > > So, my question is, how are you supposed to get a value back from COM? > > Can someone provide me with an example please? This should be simple to do > but I can't find any example of how to do it using Jawin. > > THANKS!