Not able to access a function in DLL file

Dear All,

Thanks in advance for your help. I am trying to access third party DLL file from Java first time. After going through the JNI tutorial I have done the following steps,

1. Created a Java file with 'native'functions, which are available in DLL file

public class WhereNetCOMApi

{

static

{

System.load("C:\\WNAPi\\WNOMApi");

}

public native int wNOpen (String hostname, String username, String password, Object session_id);

public native int wNSubscribe (Object session_id,String events_subscription);

}

2. Trying to call the Java function from my main function

public class WhereNetTest

{

public static void main(String arg[])

{

String sSessionID = "50005";

WhereNetCOMApi obj = new WhereNetCOMApi();

int iOpen = obj.wNOpen("","admin","admin","sSessionID");

System.out.println("Open Result : " + iOpen);

}

}

Error:

I am getting UnsatisfiedLinkError mentioning the function name. it seems to be the DLL file has been loaded, but it could not find the method.

Can any one help me to solve this issue.

Thanks & Regards,

Jose

[1203 byte] By [josemecha] at [2007-11-26 21:51:16]
# 1

> Dear All,

>

> Thanks in advance for your help. I am trying to

> access third party DLL file from Java first time.

> After going through the JNI tutorial I have done the

> following steps,

>

> 1. Created a Java file with 'native'functions, which

> are available in DLL file

>

> public class WhereNetCOMApi

> {

> static

> {

>System.load("C:\\WNAPi\\WNOMApi");

> }

>

> public native int wNOpen (String hostname, String

> g username, String password, Object session_id);

> public native int wNSubscribe (Object

> t session_id,String events_subscription);

> }

>

> 2. Trying to call the Java function from my main

> function

>

> public class WhereNetTest

> {

> public static void main(String arg[])

> {

> String sSessionID = "50005";

> WhereNetCOMApi obj = new WhereNetCOMApi();

> int iOpen =

> = obj.wNOpen("","admin","admin","sSessionID");

>

> System.out.println("Open Result : " + iOpen);

> }

> }

>

> Error:

> I am getting UnsatisfiedLinkError mentioning the

> function name. it seems to be the DLL file has been

> loaded, but it could not find the method.

Is this DLL file specifically for JNI? If yes, post the actual stack trace for the error.

Niceguy1a at 2007-7-10 3:44:27 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Need to walk through the tutorials again. When you have a 3rd party dll, you start by writing Java methods that call the functions in the dll as shown in the header file or in the generated list of signatures from a dll tool. Then you generate the JNI header file and impliment the C/C++ functions it lists. These methods handle the conversion of datatypes to C types and then actually call the dll functions in a C/C++ context and with C/C++ parameters. This JNI code is compiled into a second dll which is the dll you load in Java and because you linked it to the 3rd party dll it will in turn load it. A last note, the JNI C functions in your dll will need to be exported either using a macro and generating a .LIB file or listing them in a .DEF file.

Hope this helps,

Jim

jjones3566a at 2007-7-10 3:44:27 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
Got a pointer to an online tutorial for accessing a 3rd party dll?Thanks
JayHa at 2007-7-10 3:44:27 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
Hi,Have a look at http://jnative.sf.net--Marc ( http://jnative.sf.net)
mdentya at 2007-7-10 3:44:27 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5
The documentation is terrible.> Hi,> > Have a look at http://jnative.sf.net> > --Marc ( http://jnative.sf.net)
JayHa at 2007-7-10 3:44:27 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6
just google for "java jni wrapper dll"
bschauwejavaa at 2007-7-10 3:44:28 > top of Java-index,Java HotSpot Virtual Machine,Specifications...