Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNI to access an already written DLL

843829Feb 18 2008 — edited Feb 18 2008
New to JNI and having a nightmare trying to work this out. I've followed several tutorials but can't seem to get any of them to work in my circumstance.

I have a .dll file which has already been written and is called piapi32.dll. I'm trying to access the method piut_setservernode from this DLL file.

The code for my class is as below.
public class Main {
    /** Creates a new instance of JNITest */
    private native int piut_setservernode(String serverName);
    
    static {
        System.loadLibrary("piapi32");
    }    
    
    public Main() {
    }
    
    public static void main(String args[]) {
        try{
            Main jniTest = new Main();            
            
            int status = jniTest.piut_setservernode("ServerName");
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}
I have then used javac and javah to compile the Main.h file which contains the below.
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Main */

#ifndef _Included_Main
#define _Included_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Main
 * Method:    piut_setservernode
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_Main_piut_1setservernode
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus
}
#endif
#endif
I get an error "Exception in thread "main" java.lang.UnsatisfiedLinkError: piut_setservernode" on the line "int status = jniTest.piut_setservernode("ServerName");" when i run this program.

I've previously accessed this DLL from within Visual Basic using the below:

Declare Function piut_setservernode Lib "piapi32.dll" (ByVal servername$) As Long

Does anyone have any ideas of what i need to change or look at to get this working?

Regards

Jamie
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 17 2008
Added on Feb 18 2008
1 comment
214 views