I am working with a simple VB COM dll that has a method expecting a ParamArray (variable number of arguments). When I run the JNIWrapper codegen tool on this DLL, I get the following interface for the COM object:
_CResult runProcess(
BStr /in/ sProcess,
SafeArray /in,out/ vArgs)
Unfortunately, I can't figure out how to pass an empty array to this method (for the case when there are no additional args other than the sProcess string). I tried just null, which caused an error in the VB code. Then I tried passing new SafeArray() but that produced "Illegal access" errors.
Is there any additional documentation or advice for calling functions that use ParamArray for variable argument lists?
I could probably provide the small DLL if that would help.
TIA,
Eric
Hi Eric,
Supposing that vArgs parameter is in/out, the correct solution should be:
SafeArray vArgs = new SafeArray();
object.runProcess(new BStr("someValue"), vArgs);
Usually this approach works, but it is not clear why it may fail in your application. Therefore please send the DLL to investigate the problem and also please specify the version of JNIWrapper that you use.
Serge, thanks for your help with this.
I have attached the DLL. When I try to call the _CController.runProcess(BStr, SafeArray) method I get an Illegal access error.
I didn't write the VB code that produced this DLL, but the VB programmer didn't have any ideas why it was crashing like this.
Any insight you can provide is much appreciated - I'm trying to determine if the problem is in the way I'm using JNIWrapper, in JNIWrapper itself, or in the VB code that I'm calling.
Thanks again,
Eric
Through some experimenting, I discovered a way to get it to work.
Just to re-cap: the VB method I'm calling is expecting a ParamArray but does not currently use any of the values in that array; the JNIWrapper code generator generated a Java interface that expects a SafeArray for that argument.
I am only able to get it to work if I create the SafeArray with an explicit size and Variant.class as the explicit type - using the default no-arg constructor of SafeArray causes an "Illegal access" error.
Here is a snip of code that is working:
_CController controller = CController.create(ClsCtx.ALL);
SafeArray args = new SafeArray(0, Variant.class);
result = controller.runProcessWithParamArray(functionName, args);
Can you verify if this is "correct" or explain why the no-arg constructor for SafeArray is not working?
Hi Eric,
Yes, this is correct implementation. The runProcess method is defined as following:
_CResult* RunProcess(
in BSTR sProcess,
in, out SAFEARRAY(VARIANT)* vArgs);
where vArgs parameter is defined as in/out array of variants. Such constructor SafeArray(0, Variant.class); just correctly initializes the type of array.
Unfortunately I could not test it. I have tried to reproduce the problem using the generated files for VBPOC.DLL library, but in my case the CController.create(ClsCtx.ALL); method failed with 0x80040154(Class not registered) COM exception, though the library was registered correctly. Then I tried CController.create(ClsCtx.SERVER); but just failed with another (0x800A005B) exception. Is that attached VBPOC.DLL library correct?