Skip to content

Instantly share code, notes, and snippets.

@netmindz
Created March 3, 2011 18:49
Show Gist options
  • Select an option

  • Save netmindz/853267 to your computer and use it in GitHub Desktop.

Select an option

Save netmindz/853267 to your computer and use it in GitHub Desktop.
Buffer JNA issue
// 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);
@netmindz

netmindz commented Mar 3, 2011

Copy link
Copy Markdown
Author

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)

@netmindz

netmindz commented Mar 3, 2011

Copy link
Copy Markdown
Author

Not sure what the jna ByReference does, but byte[] definitely doesn't work

@netmindz

netmindz commented Mar 3, 2011

Copy link
Copy Markdown
Author

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