-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Best practice how to set callingConvention for a certain platform #531
Comments
I don't have a good answer for the above, but I think the world would benefit from an open-source wrapper of the Lotus Notes API. Just saying :) |
There’s already a The calling convention on callbacks looks like a bug; the convention should be pulled from a containing library option if available. If you could write a failing test for that, and put it into a PR, it’d be helpful. That’s a Java-only fix.
|
I'm wondering if it'd be easier to have platforms which haven't defined |
I also had the idea to introduce a I'm not 100% sure if I got that piece of code. On Linux64 I expected to get an "Unrecognized calling convention"-error with an In my debugging session I tracked down the problem to CallbackReference.getCallback#L131. Maybe you can take a look at this, if this should be also fixed. Can I download the 4.2.1-SNAPSHOT maven artifact somewhere from the travis-ci? If so, it should be easy for me to test your fixes. |
I’ll push a staging artifact when I get a chance, or one of the other admins can do it. @lgoldstein - I need to get you set up with java.net maven repo access. T. |
@twall I'm fairly sure have the wrong Lyor. I know the Lyor you pinged, he isn't a Java dev 😆 |
oops, I should know better than to do that via email :) thanks
|
This commit demonstrates setting calling convention based on platform: |
Hello,
in my current application I have to access the Lotus Notes C-API.
This API is available for various platforms and JNA looks perfect to access the Notes API on different platforms. (in my case: Linux/32/64 + Windows/32/64)
Although the JNA API was new for me, it was not very difficult to do this. My implementation seems t works on all platform EXCEPT on Win/32 with this problem:
Then I spent a lot of time with debugging, reading documentation, source, header files and so on to figure out what is different with Win32.
I finally figured out that I am using the wrong calling-convention for my JNA callbacks and this messed up the stack. (All Notes API functions are declared as __stdcall on Windows)
While reading the JNA sources I came over the AltCallingConvention interface, and it seems that this solves my problem. Win/32 works now - but Linux/64 (and maybe others) did not work any longer, as the __stdcall calling convention is not available there.
So I tried to change the initializer to
in the hope that ALT_CONVENTION is also used for callbacks that are passed to the Notes-API. But the flag does not count in
CallbackReference.getFunctionPointer()
:(It seems that currently the only way to change the calling convention is to tag it with
AltCallingConvention
So I ended up with the following workaround code:
The good thing: My code works on all platforms now.
The bad thing: This inflates my code with a lot of dummy classes and WIN_32 checks.
So is it possible to change the calling-convention programmatically for certain platforms, or are there plans to implement this? (maybe something like this:
options.put(Library.OPTION_CALLBACK_CALLING_CONVENTION, Function.ALT_CONVENTION);
)Best regards
Roland Praml
The text was updated successfully, but these errors were encountered: