Jni problem !!!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   champoussin_stephane
Posted On:   Wednesday, March 28, 2001 06:28 AM

I want with a java programm to call functions from a dll in c. Here is my problem : Someone give me a dll and the .h . Here is file.h : #ifndef u_char #define u_char unsigned char #endif int Code(u_char *bufout, u_char *bufin); int Decode(u_char *bufout, u_char *bufin); I have to make a java program which use the functions of the dll. But the only help i find on the web is about creating a dll. But in my case the dll already exist. So how can i do to use these functions in my java program ? Here is champou.java for example : import java.net.*;    More>>

I want with a java programm to call functions from a dll in c.
Here is my problem :
Someone give me a dll and the .h .
Here is file.h :

#ifndef u_char

#define u_char unsigned char

#endif

int Code(u_char *bufout, u_char *bufin);

int Decode(u_char *bufout, u_char
*bufin);


I have to make a java program which use
the functions of the dll.

But the only help i find on the web is
about creating a dll.

But in my case the dll already exist.

So how can i do to use these functions
in my java program ?



Here is champou.java for example :



import java.net.*;

import java.lang.*;

public class champou

{

static

{

System.load("e:\file.dll");

}

public native int Code(String a, String
b);

public native int Decode(String a,
String b);

public static void main(String args[])

{

champou essai = new champou();

int i = essai.Code
("chaine1","chaine2");

}

}



Is this the right way to implement or
not ?

If you can help me, it would be cool.

my email : stephane.champoussin@free.fr



St├ęphane...

   <<Less

Re: Jni problem !!!

Posted By:   Alexander_Krapf  
Posted On:   Friday, March 30, 2001 10:21 AM

Dear Stephane,


you have a couple of problems in your approach. Let me address them in sequence:



  • You cannot call directly into your DLL. You need to wrap your DLL with a DLL that you build. That DLL will need to implement the native methods that you declare by delegating to the methods in your target DLL.
  • String objects are immutable in Java. This means that the outbuf argument must not be a String. You can make it a StringHolder (a class that has a String field that you set with the result) or a character array which you convert to a String.
  • You need to be careful with the encoding that is used when you extract bytes from the Java input string. The default encoding might not be the correct one.

You could also check out our JunC++ion product, which might make your life significantly easier. You probably would not want to buy it if this is the total extent of your JNI problem, but if there are other parts, you might want to give it a try. Visit http://www.codemesh.com to learn more about it. Disclaimer: I am a principal there.


Good luck,


Alex

About | Sitemap | Contact