Loading a 3rd party from a java code

D

dvir shaty

Hi all,

I am trying to load a function from a 3rd party DLL from my java code
(in eclipse).

Can you please tell me how to do it?

I tried to use the following:

------------------------------------------------
package tal.packege;
class talclient
{
static
{
System.loadLibrary("talclient");
}
public static void main(String ar[])
{
System.out.println("Hello world from Java");
talclient t=new talclient();
String s = "172.16.10.31";
int a = 8888;
int b = 0;
t.tal_connect(s,a,b);

}
public native void tal_connect(String s, int a, int b);
}

------------------------------------------------


I get the following exception:


Exception in thread "main" java.lang.UnsatisfiedLinkError:
tal.packege.talclient.vtc_connect(Ljava/lang/String;II)V
at tal.packege.talclient.vtc_connect(Native Method)
at tal.packege.talclient.main(talclient.java:16)

According to the dll help file the arguments are defined as:

int tal_connect( char *servername,
Int portnum,
Int options)

The dll is stored in c:\windows\system32.


Thanks, Dvir.
 
J

Joshua Cranmer

According to the dll help file the arguments are defined as:

int tal_connect( char *servername,
Int portnum,
Int options)

How does Java know that? DLLs would just store the exported function as
"tal_connect", with no type information whatsoever, so Java has no clue
what the type information is.

If it is just a raw C DLL, you will have to write the native JNI code to
do that. Googling `JNI tutorial' should give it to you.
 
A

Arne Vajhøj

I am trying to load a function from a 3rd party DLL from my java code
(in eclipse).

Can you please tell me how to do it?

I tried to use the following:

------------------------------------------------
package tal.packege;
class talclient
{
static
{
System.loadLibrary("talclient");
}
public static void main(String ar[])
{
System.out.println("Hello world from Java");
talclient t=new talclient();
String s = "172.16.10.31";
int a = 8888;
int b = 0;
t.tal_connect(s,a,b);

}
public native void tal_connect(String s, int a, int b);
}

------------------------------------------------


I get the following exception:


Exception in thread "main" java.lang.UnsatisfiedLinkError:
tal.packege.talclient.vtc_connect(Ljava/lang/String;II)V
at tal.packege.talclient.vtc_connect(Native Method)
at tal.packege.talclient.main(talclient.java:16)

According to the dll help file the arguments are defined as:

int tal_connect( char *servername,
Int portnum,
Int options)

The dll is stored in c:\windows\system32.

JNI does not support calling arbitrary functions in a
DLL.

You need to create wrapper function and DLL that is
JNI compatible and call that.

Arne
 
I

Ian Shef

I am trying to load a function from a 3rd party DLL from my java code
(in eclipse).

Can you please tell me how to do it?

I tried to use the following:

------------------------------------------------
package tal.packege;
class talclient
{
static
{
System.loadLibrary("talclient");
}
public static void main(String ar[])
{
System.out.println("Hello world from Java");
talclient t=new talclient();
String s = "172.16.10.31";
int a = 8888;
int b = 0;
t.tal_connect(s,a,b);

}
public native void tal_connect(String s, int a, int b);
}

------------------------------------------------


I get the following exception:


Exception in thread "main" java.lang.UnsatisfiedLinkError:
tal.packege.talclient.vtc_connect(Ljava/lang/String;II)V
at tal.packege.talclient.vtc_connect(Native Method)
at tal.packege.talclient.main(talclient.java:16)

According to the dll help file the arguments are defined as:

int tal_connect( char *servername,
Int portnum,
Int options)

The dll is stored in c:\windows\system32.

JNI does not support calling arbitrary functions in a
DLL.

You need to create wrapper function and DLL that is
JNI compatible and call that.

Arne
And furthermore...
- Your code calls tal_connect, but the error message is for vtc_connect.
- char * is NOT the same as java.lang.String
 
A

Arne Vajhøj

I am trying to load a function from a 3rd party DLL from my java code
(in eclipse).

Can you please tell me how to do it?

I tried to use the following:

------------------------------------------------
package tal.packege;
class talclient
{
static
{
System.loadLibrary("talclient");
}
public static void main(String ar[])
{
System.out.println("Hello world from Java");
talclient t=new talclient();
String s = "172.16.10.31";
int a = 8888;
int b = 0;
t.tal_connect(s,a,b);

}
public native void tal_connect(String s, int a, int b);
}

------------------------------------------------


I get the following exception:


Exception in thread "main" java.lang.UnsatisfiedLinkError:
tal.packege.talclient.vtc_connect(Ljava/lang/String;II)V
at tal.packege.talclient.vtc_connect(Native Method)
at tal.packege.talclient.main(talclient.java:16)

According to the dll help file the arguments are defined as:

int tal_connect( char *servername,
Int portnum,
Int options)

The dll is stored in c:\windows\system32.

JNI does not support calling arbitrary functions in a
DLL.

You need to create wrapper function and DLL that is
JNI compatible and call that.
And furthermore...
- Your code calls tal_connect, but the error message is for vtc_connect.
- char * is NOT the same as java.lang.String

Both will somewhat become obvious when creating the
JNI wrapper.

The output from javah will show a lot.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top