Re: Help please: Trouble getting a value back from COM.
Robert Hastings <[email protected]>
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <JAWIN%[email protected]> |
Darrin,
I'm not sure this is a problem with jawin yet.
You Garbage method needs some tweaks for it to work with plain C++.
[out] parameters must be passed by reference or pointers. Since COM does not
deal with C++ references we'll use a pointer type:
STDMETHODIMP CValidateLogin::Garbage(
/*[in]*/ BSTR InputString,
/*[in]*/ int InputInt,
/*[out]*/ BSTR *returnString)
{
*returnString = CString(_T("blah")).AllocSysString();
return 0;
}
Robert
-----Original Message-----
From: Discussion of Java/Win32/COM integration with Jawin
[mailto:[email protected]] On Behalf Of Darrin Smith
Sent: Friday, June 04, 2004 9:10 AM
To: [email protected]
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!