-
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
Native Win32 API doesn't work #497
Comments
You could start by replacing all non-primitive types with primitive types, and replace String with WString, thus eliminating type mapping as a potential source of the problem. If that works, you can then re-introduce the derived types until you again encounter the error, which should isolate the problem.
|
If I use |
It’s quite possible there’s a bug in the direct mapping handling the String=>WString type converter. Try using UNICODE_OPTIONS, but explicitly declare the function to use WString as the argument type.
|
I’ve verified there’s at least a bug in automatic conversion from String to WString via type mapper when using direct mapping (and likely a corresponding bug in converting any such return type).
|
I can't test right now, but I'll take a look tonight. Anyway, happy you found a bug. I took a look yesterday and didn't find anything by reading the code. Could you explain the problem ? |
There is special handling when the call dispatch encounters a type mapper or a NativeMapped type. Unfortunately these code blocks don't account for when those things convert into a String or WString, which are arguably legitimate native types. The dispatcher is left holding a pointer to a Java object instead of a native string pointer. It's odd that your case didn't encounter an error before actually making the native call. Sent from my iPhone
|
I just tested with
And it works correctly with |
It’s turning out to be a little more complicated than I expected, mainly in handling the general case of a type mapper or NativeMapped spitting out a String, WString, or NIO Buffer (which all claim to be supported in NativeMapped javadoc). Those types require temporary allocation of memory or other setup/teardown, and while the direct mapping code accounts for that in some cases, the type mapped/native mapped code runs through a different path making it difficult to re-use the existing setup/teardown methods. Nonetheless I expect to get a fix in before the next release.
|
Ok. Thanks for your support @twall ! |
Fixed by #498 |
I tested performance of custom direct mapping of kernel32, as above, vs interface mapping which is buit-in JNA, and direct mapping seems as don't give any performace benefit. even worse, it perform a little bit slower, which is contradicting statement of direct mapping performace in the documentation |
There's an explicit performance test within the JNA test suite The JNA tests themselves run in both direct and interface mapping modes. If you're passing anything other than primitive values and pointers as On Fri, Jun 17, 2016 at 6:58 AM, boscogh notifications@github.com wrote:
|
yes, probably the case is an OVERLAPPED structure, which I use. |
…ava-native-access#497) Motivation: Quiche added support for key updates, which are required for long living connections. Lets use the version that added support Modifications: Update to 3b1e5b21977d5b4838362c460444dc758487397c Result: No more issues with long living connections
Hello,
I'm trying to bind the CreateFile function from kernel32 use direct mapping.
It correctly finds the function, but the call fails, telling that my file doesn't exist. Here is the call:
If I replace my call with with the method privded by JNA platform:
It works correctly. It might be related to the type mapping (probably the string convertion), but I don't understand why because I used the same options. Maybe I missed something and it's not a real issue.
Thanks for your amazing work.
The text was updated successfully, but these errors were encountered: