在 JNA 中定义 HGlobal
Define HGlobal in JNA
我必须将应用程序从 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.
你有什么想法,如何分三部分处理这个全局内存块?
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
typedef HANDLE HGLOBAL;
HGLOBAL 与 HANDLE 相同,因此您可以使用 W32API.HANDLE 作为 HGLOBAL
...
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);
我必须将应用程序从 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.
你有什么想法,如何分三部分处理这个全局内存块?
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
typedef HANDLE HGLOBAL;
HGLOBAL 与 HANDLE 相同,因此您可以使用 W32API.HANDLE 作为 HGLOBAL
...
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);