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

Use of ellipsis in ProxyObject #630

Closed
SevenOf9Sleeper opened this issue Apr 5, 2016 · 8 comments
Closed

Use of ellipsis in ProxyObject #630

SevenOf9Sleeper opened this issue Apr 5, 2016 · 8 comments

Comments

@SevenOf9Sleeper
Copy link
Contributor

When methods from Microsofts COM interfaces are generated there are often very long methods:
for example in _Document.SaveAs():

@ComMethod
public void SaveAs(Object fileName, Object fileFormat, Object lockComments, Object password, Object addToRecentFiles, Object writePassword, Object readOnlyRecommended, Object embedTrueTypeFonts, Object saveNativePictureFormat, Object saveFormsData, Object saveAsAOCELetter, Object encoding, Object insertLineBreaks, Object allowSubstitutions, Object lineEnding, Object addBiDiMarks);

Ok, now, you can shorten this method as you wishes:

@ComMethod
public void SaveAs(Object fileName);

The ProxyObject is so cute to deal with this shortened method.
But perhaps you now find out, that you need the next parameter: fileFormat. So: you must add the
parameter and perhaps correct the former calls with the one parameter...

So my question is: would it not much better if we can use the ellipsis feature from java to generate an additional method like this:

@ComMethod
public void SaveAs(Object... someArgs);

Now we can call the method with as many parameters as we wish. :-)

Any opinions to this? Would it be a problem, when you want to transfer real arrays as parameters? But when I am right, then there is no SAFEARRAY-handling in the COM.util.Convert class (so far).

SevenOf9Sleeper added a commit to SevenOf9Sleeper/jna that referenced this issue Apr 5, 2016
@SevenOf9Sleeper
Copy link
Contributor Author

How can I get a "feature request" label for this issue?

@dblock
Copy link
Member

dblock commented Apr 6, 2016

we sell those :)

@SevenOf9Sleeper
Copy link
Contributor Author

Very well... ;-) Bought.

@SevenOf9Sleeper
Copy link
Contributor Author

What must I keep in mind when I create unit tests? On which platform will they be executed? Which COM objects can I expect to be there?

@matthiasblaesing
Copy link
Member

The unittests are filtered by platform (see the existing tests) (build.xml, lines 115-123). I'd suggest you place the test for vararg calls in ProxyObject_Test.java.

The COM objects, well choose something everybody has. There are office based tests, but I'd try to stay away from that, for example I'm on a test version which will expire. IE should be available everywhere, ShellUtils.

Thinking about varargs: Navigate2 from the IWebBrowser2 interface could be a good candidate.

SevenOf9Sleeper added a commit to SevenOf9Sleeper/jna that referenced this issue Apr 7, 2016
SevenOf9Sleeper added a commit to SevenOf9Sleeper/jna that referenced this issue Apr 7, 2016
@SevenOf9Sleeper
Copy link
Contributor Author

@matthiasblaesing you answered to my recent commit:

java reflection can give you info whether the method is a varargs call (Method#isVarArgs), this should eliminate the danger to collide with array arguments

Hmm... that's right. But in the method invokeMethod(Class<T> returntype, String name, Object... args) I have no access to the method-object. And I can't give it in from invoke(Object proxy, Method method, Object[] args) because invokeMethod overrides invokeMethod from COM.util.IDispatch... :-]

So, how to deal with this? Global variables? :-) ok, just kidding...
Or I stick a yellow label at the bottom of the args-parameter? ;-)

SevenOf9Sleeper added a commit to SevenOf9Sleeper/jna that referenced this issue Apr 7, 2016
@matthiasblaesing
Copy link
Member

Move the logic to ProxyObject#invoke - there you have the method for reflection and the arguments in their caller shape, unwrap/rewrap it and pass it on to invokeMethod.

SevenOf9Sleeper added a commit to SevenOf9Sleeper/jna that referenced this issue Apr 10, 2016
SevenOf9Sleeper added a commit to SevenOf9Sleeper/jna that referenced this issue Apr 10, 2016
dblock added a commit that referenced this issue Apr 23, 2016
feature #630: use of ellipsis/varargs in COM methods
@SevenOf9Sleeper
Copy link
Contributor Author

Merged with 4b7421c
So I close this issue.

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

No branches or pull requests

3 participants