Here is what I have tried:
A test DLL com control was created using the same vb6 compiler so I can share the DLL if anyone wants to try.
COM control does some debugmessage outputs and adds 10 to the passed in number. That is it.
Full vb6 source:
Option Explicit
Public Enum eProjectReturnCode
RETURN_ERROR = 0
RETURN_OK = -1
RETURN_USER_CANCEL = -2
End Enum
Private Declare Sub OutputDebugString Lib "kernel32" Alias "OutputDebugStringA" (ByVal lpOutputString As String)
Public Function ProjectCountTest(lNumberOfProjects As Long, Optional ByVal sPdsg As String) As eProjectReturnCode
OutputDebugString "ProjectCountTest start" + Chr(13) + Chr(10)
OutputDebugString "ProjectCountTest passed in long " + Str(lNumberOfProjects) + Chr(13) + Chr(10)
OutputDebugString "ProjectCountTest passed in string [" + sPdsg + "]" + Chr(13) + Chr(10)
lNumberOfProjects = lNumberOfProjects + 10
OutputDebugString "ProjectCountTest returning " + Str(lNumberOfProjects) + Chr(13) + Chr(10)
ProjectCountTest = RETURN_OK
OutputDebugString "ProjectCountTest setting return to OK, may change" + Chr(13) + Chr(10)
If (Len(sPdsg)) > 0 Then
If sPdsg = "AER" Then
ProjectCountTest = RETURN_ERROR
OutputDebugString "ProjectCountTest setting return_error" + Chr(13) + Chr(10)
ElseIf sPdsg = "BUC" Then
ProjectCountTest = RETURN_USER_CANCEL
OutputDebugString "ProjectCountTest setting return_user_cancel" + Chr(13) + Chr(10)
End If
End If
End Function
generated java classes
@ComObject(clsId = "{5D1B16BD-41DD-47B1-9D2C-21627949AE7D}")
public interface COMTester extends IUnknown
,_COMTester
{
}
@ComInterface(iid="{C4B5FC56-593D-4935-B7E2-C9B3B05F2541}")
public interface _COMTester extends IUnknown, IRawDispatchHandle, IDispatch {
/**
* <p>id(0x60030000)</p>
* <p>vtableId(7)</p>
* @param lNumberOfProjects [inout] {@code Integer}
* @param sPdsg [in, optional] {@code String}
*/
@ComMethod(name = "ProjectCountTest", dispId = 0x60030000)
eProjectReturnCode ProjectCountTest(VARIANT lNumberOfProjects,
String sPdsg);
}
Send in 1 expect 11 back for the vb LONG java int variable. Never get 11 back.
public class ComTest001 {
public static void main(String[] args) throws IOException {
WinNT.HRESULT hr = Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_APARTMENTTHREADED);
COMUtils.checkRC(hr);
Factory fact = new Factory();
try {
System.out.println("A");
COMTester comtest = fact.createObject(COMTester.class);
System.out.println("B");
int one = 1;
//IntByReference length = new IntByReference(one);
//VARIANT vp = new VARIANT(length);
//C int@0x5d7dc0=0x1 (1)
//Exception in thread "main" com.sun.jna.platform.win32.COM.COMInvokeException: Type mismatch.(HRESULT: 80020005) (puArgErr=1)
//VARIANT vp = new VARIANT(one);
// runs but vp does not contain value set in com method.
//IntByReference length = new IntByReference(one);
//VARIANT.ByReference vp = new VARIANT.ByReference(length.getPointer());
//Exception in thread "main" java.lang.IllegalArgumentException: Structure exceeds provided memory bounds
//at com.sun.jna.Structure.useMemory(Structure.java:372)
//.. Caused by: java.lang.IndexOutOfBoundsException: Bounds exceeds available space : size=4, offset=16
// VARIANT v = new VARIANT(one);
// VARIANT.ByReference vp = new VARIANT.ByReference(v.getPointer());
// runs but vp / v do not contain value set in com method.
//VARIANT v = new VARIANT(one);
//VARIANT.ByReference vp = new VARIANT.ByReference(v);
// runs but vp / v do not contain value set in com method.
VARIANT v = new VARIANT(one);
VARIANT vp = new VARIANT(v.getPointer());
// runs but vp / v do not contain value set in com method.
System.out.println("C " + vp.getValue());
eProjectReturnCode rc = comtest.ProjectCountTest(vp, "");
System.out.println("D " + rc);
System.out.println("E " + vp.getValue());
System.out.println("EE " + v.getValue());
} finally {
fact.disposeAll();
Ole32.INSTANCE.CoUninitialize();
}
}
output
E/ EE should be 11 for a valid run.
debugmessages
[8896] ProjectCountTest start
[8896] ProjectCountTest passed in long 1
[8896] ProjectCountTest passed in string []
[8896] ProjectCountTest returning 11
[8896] ProjectCountTest setting return to OK, may change