Created
March 3, 2011 18:49
-
-
Save netmindz/853267 to your computer and use it in GitHub Desktop.
Buffer JNA issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C++ header | |
extern "C" __declspec(dllexport) int __stdcall API_USBMF_Request( | |
HANDLE commHandle, int DeviceAddress, | |
unsigned char inf_mode, unsigned char *Buffer); | |
// Java - Returns a single byte, which I think is a valid result | |
public int API_USBMF_Request(HANDLE commHandle, int DeviceAddress, char inf_mode, ByteByReference Buffer); | |
// Java - No change to byte array | |
public int API_USBMF_Request(HANDLE commHandle, int DeviceAddress, char inf_mode, byte[] Buffer); | |
I just tried using PointerByReference, and that appears to kind of give me something. If i toString the Pointer i get a nice native@0x123456 kinda thing, so i just need to work out how to to the Pointer equivalent of Native.toString(byte[] blah)
Not sure what the jna ByReference does, but byte[] definitely doesn't work
Any ideas why using Pointer.getString() failed with access exception, weridly using IntByReferernce returns values, though quite what this number is when what I want is a String I'm not sure. Some native thing ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure about JNA, but if I was mapping the function with HawtJNI it would look like this:
Data get copied out the java objects and then back by default. But if you know that the Buffer is write only, the you can optimize by adding the
NO_IN
flag: