简体   繁体   中英

JNA with 32bit JVM on a 64bit OS

I want to upgrade a device using a proprietary library (DLL) that I developed. The library works fine using a MFC app. However, the twist here is that we must make this work in a browser .

My idea was to use an applet and then call the native DLL to make this work. Everything was working fine with my test Java application. Then I tried with the applet and then nothing worked.

I've narrowed down the problem to 32bit VS 64bits JVM. Let me explain : the Eclipse IDE that I am using uses a 64bit JVM since I am on Windows 7 64bit . The browser, however, uses a 32bit JVM and that doesn't work.

The difference between the two are the parameters passed to my function. Here's some examples of the functions that the DLL exposes :

bool UPGRADELIB_API Connect( const char* serverAddress, unsigned short serverPort );
bool UPGRADELIB_API Upgrade( const char* pFilePath );

Which are respectively matched in Java by :

boolean Icon_ConnectClientNode( String serverAddress, int serverPort );
boolean Icon_Upgrade( String pFilePath );

My Java test GUI passes to this native lib "192.168.xx" for the IP address and 50005 for the port. In 64bit , everything is fine, as I said earlier. In 32bit , if I print serverAddress and serverPort in C, it shows

(null):62384

As you can see, even the port is not passed correctly.

I've been on this for a week now, I am pulling so much hair from my head that I won't have any soon... please help me!

Found the error : was passing a long and the Java long is not the same size as the C/C++ long in 32bit and 64bit.

Silly me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM