kohsuke / com4j

Type-safe Java/COM binding
http://com4j.kohsuke.org/
BSD 2-Clause "Simplified" License
146 stars 78 forks source link

Cannot convert Variant to double[] #84

Open dhiegorp opened 4 years ago

dhiegorp commented 4 years ago

I have an interface signature in a dll

[id(0x0000001d), propget, helpstring("property Contaminants")]
HRESULT Contaminants([out, retval] VARIANT* pVal);

Whose specification tells me that it returns an array of double of a fixed length and which I could attest to be correct via VBA code. The generated java code for this method was:

@DISPID(29) //= 0x1d. The runtime will prefer the VTID if present
  @VTID(55)
  @ReturnValue(type=NativeType.VARIANT)
  Object contaminants();

The problem is that any calls to this method result in a null value. I tried to map this in different ways, some resulting in conversion errors (exceptions), some of them resulting in JVM dump. The best that I could do was "remap" the method to receive a Variant instance as argument:

  @DISPID(29) //= 0x1d. The runtime will prefer the VTID if present
  @VTID(55)
  @ReturnValue(type=NativeType.VARIANT)
  void  getContaminants(Variant variant);

Passing a brand new Variant to the method I could confirm that the variant instance was updated (its "image" buffer changed value). Calling getType() return me a Variant.Type.VT_ARRAY_R8, which was the expected (equivalent to a double[]) although, any attempts to return an Object or a double[] result in null values ( Variant#get, Variant#convertTo).

Someone had the same problem or have any clues to solve this?

I have to say that I'm using the COM4J zip package, which seems to be quite old concerning the commits to the master branch.