Thank you, Matthias, for chiming in. Your input is highly appreciated!
Unfortunately your code did not work: After the call the variant still has the type vt_empty! So I tried to resemble what JACOB actually does internally, and that successfully worked:
var ref = new WinDef.LONGByReference();
var handleRef = new VARIANT();
handleRef.setValue(VT_I4 | VT_BYREF, ref);
c.clientConnect(handleRef, moduleID, languageID, userID, userPwd);
var handle = ref.getValue().intValue();
NB: TLB / TLD files literally say "
long", but both were authored on a 32 Bit machine, and the COM server actually is a 32 Bit EXE, so according to
https://learn.microsoft.com/en-us/windows/win32/midl/long this means: (quote)
"On 32-bit platforms, long is synonymous with int." (looking at the date when this document was originally authored, what they actually meant to say is: "on
all non 16-bit platforms"), hence in Java it must be "
int"!
I assume that this fact was not known or ignored by the original author of the COM-Support in JNA, as JNA internally seems to think that an IDL "long" should be a Java "long", while it must be a Java "int" always. Could somebody please confirm this?
NB: Surprisingly, JNA does not like to accept IntByReference or LongByReference here, but it really must be WinDef.LONGByReference! Apparently no support for IntByReference or LongByReference exists in JNA's VARIANT class, which one simply has to know (I couldn't find any documentation about that. If it exists I would be happy for a pointer!).
From here, it should not be too far to a production-grade solution:
Question 1: Is there a simpler / more convenient / otherwise "better" way in JNA to achieve that?
Question 2: Do I have to manually free or clear any resources?
Question 3: Why is the above solution not happening automatically (internally in JNA) when using the following code (I assume the cause is JNA's misconception that an IDL "long" should be a Java "long", see above comments / please confirm)?
@ComMethod(name = "ClientConnect")
void clientConnect(IntByReference handle, int moduleID, int languageID, String userID, String userPwd);
Thanks a lot! JNA is great!
👍