我必须将应用程序从C ++翻译成Java,但它使用dll,所以我必须使用JNA。应用程序应扫描设备中的内容。这是C ++中的应用程序:
//HEADERS
ABC_Shell = (int (*)(char* cmd, int len, char* rsp, int buflen))GetProcAddress(g_hLib, "ABC_Shell");
ABC_ImageProcessFromRaw = (int (*)(HGLOBAL hFront, HGLOBAL hRear))GetProcAddress(g_hLib, "ABC_ImageProcessFromRaw");
//END
HGLOBAL hImage[3];
memset(hImage, 0, sizeof(hImage));
nRet = ABC_Shell("CP12", strlen(szShell), (char*)hImage, sizeof(hImage));
ABC_ImageProcessFromRaw(hImage[0], hImage[1]); //FACE, BACK RGB IMAGE
ABC_ImageProcessFromRaw(hImage[2], NULL); //FACE IR IMAGE
SaveImage(0, hImage[0], hImage[1], hImage[2]);
以下是Java:
//HEADERS
int ABC_Shell(String command, int len, byte[] response, int buflen);
int ABC_ImageProcessFromRaw(byte[] hFront, byte[] hRear);
//END
byte[] response = new byte[64];
api.ABC_Shell("CP12", 8, response, 1024); // it works, but response is strange
api.ABC_ImageProcessFromRaw(response, null);
当然设备正在扫描,但我不知道用什么样的变量来做出响应,然后在下一个函数中使用它。在C ++中是HGlobal [3],在JNA中没有类似的东西。我在这看 - https://jna.java.net/javadoc/platform/com/sun/jna/platform/win32/W32API.html。
您有什么想法,如何处理这个全局内存块分为三个部分?
答案 0 :(得分:2)
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
typedef HANDLE HGLOBAL;
HGLOBAL与HANDLE相同,因此您可以将H32API.HANDLE用于HGLOBAL
答案 1 :(得分:1)
...
int ABC_Shell(String command, int len, Pointer[] response, int buflen);
int ABC_ImageProcessFromRaw(Pointer hFront, Pointer hRear);
...
Pointer[] response = new Pointer[3];
// You should probably be more programmatic about the command buffer and its length
api.ABC_Shell("CP12", 8, response, response.length * Pointer.SIZE);
api.ABC_ImageProcessFromRaw(response[0], null);