Skip to main content
gamedev.net
🔒 Locked

[java] java and dll

Started by gelerorox 9 replies 2.1k views
Original Post
gelerorox
gelerorox
Hey guys! I need help here! How can I call a public method inside a given dll ? Well, did you know TeamSpeak ? see www.goteamspeak.com Take a look at this forum: http://forum.goteamspeak.com/forumdisplay.php?f=60 and at this thread: http://forums.planetice.net/showmessage.php?message_id=276497 How can I acess those fields and those methods ? I know the way is JNI, but how ? Thank you!
gelerorox
gelerorox
Well, let me improve my question:

JAVA snippet code:

I got this class:

package br.com.rsl.util.ts;
public class TS {

public native Integer tsrConnect(String url);
public native void tsrDisconnect();

static {
System.loadLibrary("TSRemote");
}
}

and this code:

public static void main(String[] args) {
TS ts = new TS();
ts.tsrConnect("teamspeak://ts.ig.com.br:9500");
}


and unfortunately, this error:

java.lang.UnsatisfiedLinkError: tsrConnect
at br.com.rsl.util.ts.TS.tsrConnect(Native Method)
at br.com.rsl.util.ts.teste.main(teste.java:9)



The library loading is ok. So the virtual machine have knowledge of the dll. But for some reason I cant call the method!
Why ?
gelerorox
gelerorox
Well, can you speak slowly please!?
hehe

Thats the function from developer's sdk:

/##############################################################################
//#
//# Function tsrConnect(URL :Pchar): integer
//#
//# Description:
//# Connect the ts to a new server as described in the URL. Will disconnect
//# if the client is currently connected. The Url is the same format as the
//# normal starup link ("teamspeak://voice.teamspeak.org:9500" etc)
//#
//# Input:
//# URL: A pointer to a null terminated string containing the url for the
//# server.
//#
//# Output:
//# Result: 0 = OK, else the error number
//#
//##############################################################################
type TtsrConnect = Function (URL :Pchar): Integer;{$ifdef linux}cdecl;{$endif}{$ifdef mswindows}stdcall;{$endif}
var tsrConnect : TtsrConnect;
const fn_tsrConnect='tsrConnect';


So, my native function is alright?? With that string as parameter ?


After, this I have to call javah to create a C++ header ? Why ? What should I do with this header if the DLL is good to go ?

gelerorox
gelerorox
Well. My code is java.

The code inside "######" grid isnt mine and actually is a document just explaining the structure of any TeamSpeak method inside the DLL.

And come on! Plain old C functions ?!?! Why !? I really dont think so.

And that error:
"java.lang.UnsatisfiedLinkError: tsrConnect" is about not finding "tsrConnect" method! That method is waiting as parameter a PCHAR variable. And I am passing a String. Is this correct ?


gelerorox
gelerorox
hmmmmmmmm... Now I see the requirement for another dll.

that pretty anoying by the way.
Raghar
Raghar
I'd recomend you to use assembly. MASM32 and using dll created by assembler would teach you JNI properly.
gelerorox
gelerorox
WHOA!

Well, I think that asm is too much for me. Even though that I dont have time to put some effort on learning asm right now.
:(

I will have to deliver a delphi's dll (brigde) to reach the main dll.
Thanks for the tips anyway!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.