jacob-project
jacob-project copied to clipboard
Cannot get output parameter from invoke
Hello there,
I cannot manage to get output parameter from a method that has 1 input and 1 output parameter. Sub PLMCreate((iString, oEditor)
The only way to have something working is to write down the following sequence Variant editor = new Variant (null, true); editor.putNothing(); Dispatch.invoke(plmNewService.getDispatch(), "PLMCreate", Dispatch.Method, new Object[] {"somestring", editor}, new int[1]);
The first two lines are there to declare a Variant of VariantDispatch type, then the invoke is called.
Any other combination does not work (inverting parameters as suggested somewhere does not work, removing putNothing does not work because editor is not of the good type - VariantDispatch - , etc.)
after this call, the variable editor is a Variant answering true to isNull() method, in other word it is empty.
This call works great when called directly in VBA.
I have looked at Dispath::invokev source code, and it appears the following line is handling this case (inout parameters) https://github.com/freemansoft/jacob-project/blob/f20f5c46f992ad7e19a5864dc320fcdac913a998/jni/Dispatch.cpp#L510
do you know why I do not get a proper return value in editor ?
Many thanks for your help ! This lib is amazing !
Sad that the question has not been answered after so long. I have various such situations where vba works fine but it is impossible to make jacob work with such inout parameters.
Thanks @plehal for your support. Once, I downloaded the code and compiled it in debug mode to understand a little bit deeper, but I had to stop at some point. Basically I was stuck at the memory sharing mechanism in JNI call. Pretty sure the solution is not hard to find though, I hope one day I can put the effort back on and find a solution to this.
Variant editor = new Variant (null, true);
is sufficient. Remove the line
editor.putNothing();
After the call the editor
variable should contain the output parameter value. Works for me.