Pregunta

I am trying to write a Java applet to connect to a bar-code scanner and read the data. The bar-code scanner comes with a dll file with functions to access it. I don't have a lot of experience with Java but I've figured out how to use JNA to load the dll and call the native functions. Some of the functions work fine but the one that returns the actual bar-codes I can't seem to get to work. It takes a character array as an argument and pass by reference is not in JNA, I've tried using the Pointer class and can't get anything to work. The native functions definition is as follows.

NoMangle long DLL_IMPORT_EXPORT csp2GetPacket ( char szBarData[],long nBarcodeNumber,long nMaxLength )

After the function call the szBarData[] variable is supposed to contain the bar-code data.

I've tried setting up the JNA map several different ways, making the szBarData[] argument a char array, string, a byte array, and a pointer, and have had no luck.

in visual basic you can pass the szBarData[] a string and it works, just not sure how to accomplish this in Java using JNA.

¿Fue útil?

Solución

Since you're expecting the target function to fill in your buffer, you cannot pass a String (which is read-only) but must instead pass a byte[].

Also make sure you're not using Java long to represent native long; the class NativeLong exists for that purpose.

If what you get back is a NUL-terminated C string, then you can use Native.toString(byte[]) to convert to a String.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top