[prev in list] [next in list] [prev in thread] [next in thread]
List: ms-java-com
Subject: jactivex generates "type=PTR" instead of "ARRAY" for returned enum
From: Carl Clefstad <carl.clefstad () SANDIEGOCA ! NCR ! COM>
Date: 1999-01-30 1:18:16
[Download RAW message or body]
Can some please explain this:
I have a COM method that returns an "enum" value. I call this method from Java.
When I use the 'retval' IDL attribute, everything works fine, but when I omit
it and try to return the value as a parameter, I get (after changing my Java
code as needed) a runtime "java.lang.OutOfMemoryError" on the method call.
The IDL looks something like this:
========================
typedef enum tagCOLOR
{
UNKNOWN = 0,
RED,
GREEN,
BLUE,
... (actually has about 36 items in the list
} COLOR;
interface IColored : IUnknown
{
HRESULT GetColor( [out, retval] COLOR* piStatus );
}
coclass Thing
{
[default] interface IColored;
}
========================
The C++ implementation looks something like this:
========================
HRESULT CThing::GetColor( COLOR* piColor )
{
if( piColor == NULL )
return E_POINTER;
*piColor = m_iMyColor;
// Return indication if color is florescent
if( m_bFlorescent )
return S_FALSE;
return S_OK;
}
========================
When I run jactivex, it generates:
========================
// Auto-generated using JActiveX.EXE 5.00.2924
// (jactivex /javatlb MyServer.tlb )
...
package xyx;
...
// VTable-only interface IColored
/** @com.interface(iid=56632866-0FB2-11D2-9227-00E0290899BF, thread=AUTO) */
public interface IMCChassis extends IUnknown
{
/** @com.method(vtoffset=4)
@com.parameters([type=I4] return) */
public int GetColor();
...
}
========================
In Java, I call it like so:
========================
int color = tagCOLOR.UNKNOWN;
boolean florescent = false;
try {
color = iColored.GetColor();
} catch (ComSuccessException e) {
// S_FALSE returned ... "color" contains a florescent color
// is color set?
System.out.println("getColor returned S_FALSE, color is florescent");
florescent = true;
} catch (ComFailException e) {
// handle error
}
System.out.println("GetColor returned: " + color);
========================
That works fine (except I can't get florescent colors because the returned
color when ComSuccessException is thrown will not be set!).
Here's the main problem: When I omit 'retval' from the IDL (because I want
to see if I can get florescent colors returned), the Java stub and my code
change as shown below ... but I always get a "java.lang.OutOfMemoryError" at
runtime during the call to GetColor().
New jactivex-generated Java stub:
========================
/** @com.method(vtoffset=4)
@com.parameters([out,type=PTR] piColor) */
public void GetColor(int[] piColor);
========================
My new Java code:
========================
int[] color = new int[1]; color[0] = tagCOLOR.UNKNOWN;
boolean florescent = false;
try {
iColored.GetColor(color); // <- throws OutOfMemoryError!!!
} catch (ComSuccessException e) {
// S_FALSE returned ... "color" contains a florescent color
// is color set?
System.out.println("getColor returned S_FALSE, color is florescent");
florescent = true;
} catch (ComFailException e) {
// handle error
}
System.out.println("GetColor returned: " + color[0]);
========================
If I hand-edit the jactivex-generated Java stub, changing:
@com.parameters([out,type=PTR] piColor) */
to:
@com.parameters([out,size=1,type=ARRAY] piColor) */
then it works (and my 'florescent color' gets returned correctly).
Why does jactivex generate "type=PTR" when in fact the type should be "ARRAY"?
Is this a jactivex bug?
--
***********************************************
Carl Clefstad, NCR Corporation
Email: carl.clefstad@sandiegoca.ncr.com
***********************************************
----------------------------------------------------------------
Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe. Save time, search
the archives at http://discuss.microsoft.com/archives/index.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic