I want with a java programm to call functions from a dll in c.

Alexander Krapf

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,