无法使用JAVA中的JNA调用C方法
嗨,我有这个错误,我不知道如何修复 c代码是无法使用JAVA中的JNA调用C方法,java,jna,stringbuffer,Java,Jna,Stringbuffer,嗨,我有这个错误,我不知道如何修复 c代码是 extern int APIENTRY LSGetDocData(short hConnect, HWND hWnd, unsigned long *NrDoc, LPSTR FilenameFront, LPSTR FilenameBack
extern int APIENTRY LSGetDocData(short hConnect,
HWND hWnd,
unsigned long *NrDoc,
LPSTR FilenameFront,
LPSTR FilenameBack,
LPSTR Reserved1, // not used must be NULL LPSTR Reserved2, // not used must be NULL LPHANDLE *FrontImage,
LPHANDLE *BackImage,
LPHANDLE *Reserved3, // not used must be NULL LPHANDLE *Reserved4, // not used must be NULL LPSTR CodelineSW,
LPSTR CodelineHW,
LPSTR BarCode,
LPSTR CodelinesOptical,
short *DocToRead,
long *NrPrinted,
LPVOID Reserved5, // not used must be NULL LPVOID Reserved6);
我的Java方法是
public int LSGetDocData(short hConnect, int hWnd, long[] NrDoc, String FilenameFront, String FilenameBack, String Reserved1, String Reserved2, int[] FrontImage, int[] RearImage,
int[] FrontImage2, int[] RearImage2, StringBuffer CodelineSW, StringBuffer CodelineHW, StringBuffer Barcode, StringBuffer CodelinesOptical, short[] DocToRead, long[] NrPrinted,
int Reserved5, int Reserved6);
public int lSGetDocData(long[] nrDoc, int[] frontImage, int[] rearImage,StringBuffer micrHW, StringBuffer barcode,StringBuffer micrSW,StringBuffer codeLineOptical) {
return LsApi.call.LSGetDocData(hConnect[0], hWnd, nrDoc, "imageF", "ImageR", null, null, frontImage, rearImage, null, null, micrSW, micrHW, barcode, codeLineOptical, new short[0], new long[0], 0, 0);
}
错误是
java.lang.IllegalArgumentException:不支持的参数类型
函数LSGetDocData的参数11处的java.lang.StringBuffer
我尝试将StringBuffer转换为String-Char-Pointer-Memory,应用程序显示了这个错误
invalid access memory
所以如果有人知道如何将StringBuffer转换为??
我将永远感激你
提前感谢还有谁能告诉我如何将LPSTR函数修改为JNANative
long
!=Javalong
。在windows上,本机long
始终为32位;Javalong
为64位。另请参阅上的常见问题解答(您不使用StringBuffer)。如何解决此问题?我更改字节[]{256}的lpstr。使用byte[]
/Native.toString(byte[])
或char[]
/Native.toString(char[])
需要传递缓冲区而不是字符串常量。