Results 1 to 8 of 8
  1. #1
    nikkadim is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default JNA access to 64-bit DLL (Windows7 64-bit)

    Hello,

    Could you please advice. I have simple DLL (under Windows 7 64-bit) and simple Java code with JNA access to this DLL.
    The problem is when I use 64-bit version of this DLL looks like I can't get parameter from Java in my DLL test function giveIntGetInt, and I have no problem when I use 32-bit DLL.
    Could you please explain where I wrong?
    Thank you!!


    Java code:
    Java Code:
    import com.sun.jna.Library;
    import com.sun.jna.Native;
    import com.sun.jna.Platform;
    import com.sun.jna.Pointer;
     
    /** Simple example of native library declaration and usage. */
    public class HelloWorld {
        public interface simpleDLL extends Library {
            simpleDLL INSTANCE = (simpleDLL) Native.loadLibrary(
                (Platform.isWindows() ? "simpleDLL" : "simpleDLLLinuxPort"), simpleDLL.class);
             int giveIntGetInt(int a);               // int giveIntGetInt(int a);
        }
        
        public static void main(String[] args) {
         int b = simpleDLL.INSTANCE.giveIntGetInt(2);
         System.out.println("Hello, World\n");
            
         System.out.println(String.format("Argument %d", b));
            
        }
    }
    C dll code:
    Java Code:
    int simpleDLL::giveIntGetInt(int a)
        {
            return 2*a;
        }

    For example, this is I've got with 64-bit dll:

    Hello, World
    Argument 181140



    32-bit dll:

    Hello, World
    Argument 4
    Last edited by nikkadim; 11-08-2012 at 11:15 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: JNA access to 64-bit DLL (Windows7 64-bit)

    What version of Java have you got?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    nikkadim is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: JNA access to 64-bit DLL (Windows7 64-bit)

    Quote Originally Posted by Tolls View Post
    What version of Java have you got?
    I'm used last Eclipse(eclipse-SDK-4.2.1-win32-x86_64) with jre7 64-bit (and 32-bit for 32-bit dll).

    C:\Program Files (x86)\Java\jre7\bin>java -version
    java version "1.7.0_09"
    Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
    Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)
    C:\Program Files\Java\jre7\bin>java -version
    java version "1.7.0_09"
    Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
    Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
    Last edited by nikkadim; 11-09-2012 at 02:47 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: JNA access to 64-bit DLL (Windows7 64-bit)

    Can you get the DLL code to log the value it thinks it's getting?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    nikkadim is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: JNA access to 64-bit DLL (Windows7 64-bit)

    Quote Originally Posted by Tolls View Post
    Can you get the DLL code to log the value it thinks it's getting?
    yes, I already modified code:
    Java Code:
    	int simpleDLL::giveIntGetInt(int a)
    	{
    		//a = 22;
    		FILE *stream;
    		if ((stream = fopen("g:\\TEST.dat", "wt ")) == NULL) 
    			return 0;
    		fprintf (stream, "%d",a);
    		fclose(stream);
    
    		return a;
    	}
    and I always get "-2147393078" in this file, and it's not depend on value of 'a'.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: JNA access to 64-bit DLL (Windows7 64-bit)

    I wonder if it's down to the size of the int on the C code?
    Just off the top of my head, because that is remarkably close to int-min for a 32 bit integer.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    nikkadim is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: JNA access to 64-bit DLL (Windows7 64-bit)

    Quote Originally Posted by Tolls View Post
    I wonder if it's down to the size of the int on the C code?
    Just off the top of my head, because that is remarkably close to int-min for a 32 bit integer.

    For C int should be in range -2147483648 <-> +2147483647.
    But I also tried with other type, with other dll, with long I have the same value -2147393078, with boolean I always get true, etc.
    Last edited by nikkadim; 11-09-2012 at 04:07 PM.

  8. #8
    nikkadim is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: JNA access to 64-bit DLL (Windows7 64-bit)

    Still unresolved.

Similar Threads

  1. Replies: 3
    Last Post: 11-05-2012, 05:15 AM
  2. Uninstall Apache tomcat in windows7
    By farshad in forum Apache Commons
    Replies: 1
    Last Post: 02-17-2012, 07:17 PM
  3. Replies: 0
    Last Post: 04-16-2011, 08:22 AM
  4. Replies: 0
    Last Post: 02-22-2011, 10:55 AM
  5. Default Access (package access) confusion
    By gauravrajbehl in forum New To Java
    Replies: 1
    Last Post: 11-18-2009, 10:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •