Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to set ComProperty with arguments #1073

Closed
joerg1985 opened this issue Mar 12, 2019 · 3 comments
Closed

Not able to set ComProperty with arguments #1073

joerg1985 opened this issue Mar 12, 2019 · 3 comments

Comments

@joerg1985
Copy link
Contributor

Provide complete information about the problem

  1. Version of JNA and related jars: 5.2.0
  2. Version and vendor of the java virtual machine: openjdk 11.0.2
  3. Operating System: Windows 10
  4. System architecture (CPU type, bitness of the JVM): x64
  5. Complete description of the Problem:

Setting a ComProperty with arguments allways only takes the first Argument.

We try to call this https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.irange.value as a ComProperty.

The IDL definition of this property is:
[propget, helpcontext(0x00023358)]
HRESULT _stdcall Value(
[in, optional] VARIANT RangeValueDataType,
[in, lcid] long lcid,
[out, retval] VARIANT* RHS);
[propput, helpcontext(0x00023358)]
HRESULT _stdcall Value(
[in, optional] VARIANT RangeValueDataType,
[in, lcid] long lcid,
[in] VARIANT RHS);

The JNA bindings are:

@ComProperty(name = "Value")
Object getValue(Object RangeValueDataType);

@ComProperty(name = "Value")
void setValue(Object RangeValueDataType, Object value);

I tryed to call it like this, but the cell is still empty:
range.setValue(Variant.VARIANT_MISSING, "test");

I tryed to call it like this, but the cell is filled with "10":
range.setValue(10, "test");

While debugging if found the following lines in ProxyObject#invoke, ignoring all the args with index > 0. i think this might be the reason for this.
if(dispId != -1) {
this.setProperty(new DISPID(dispId), args[0]);
return null;
} else {
String propName = this.getMutatorName(method, prop);
this.setProperty(propName, args[0]);
return null;
}

  1. Steps to reproduce:
    I could provide an example running Excel 2016 and setting a cell, if needed?
@matthiasblaesing
Copy link
Member

Could you please have a look at https://github.com/matthiasblaesing/jna/tree/github-1073 - that should do it. (Please note, that branch contains the default method on interfaces patch).

@joerg1985
Copy link
Contributor Author

@matthiasblaesing 👍 works fine now.

I tested the following call and it passes the arguments as expected and the text of the cells changes.
range.setValue(Variant.VARIANT_MISSING, "test");

thanks for your support!

@matthiasblaesing
Copy link
Member

Thanks for testing. Merged the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants