On Aug 3, 2007, at 11:16 AM, bbc2 wrote:
So, how would I write the JNA for this C function out of a
Windows .dll?
BOOL DLLEXPORT f(
BYTE *a,
short b,
long c,
BYTE d,
BOOL e);
I tried
int f(
byte[] a,
short b,
int c,
byte d,
int e);
but that crashed HotSpot.
DLLEXPORT is apparently either __declspec(dllexport) or __declspec
(dllimport)
I'm not sure what BOOL and BYTE are, but guess they are some
standard Windows thing. I guess that's my first problem. Anybody
know?
Look up their definitions on MSDN or the visual C header files. BOOL
is an int (java int), BYTE is a signed char (java byte). If you look
at W32TypeMapper you can see how to automatically translate a Java
boolean into its native equivalent (Integer), so you can use boolean
instead of int.
However, what you've mapped should work and not crash the VM; are you
using StdCallLibrary if the dll uses the __stdcall calling convention
(usually this shows up as some macro like "WINAPI" or "WINUSERAPI" or
some such cruft)?
Also make sure that the native code doesn't run off the end of your
byte array.