JNA using C DLL -


i'm using jna c dll file , have exception can't resolve:

java.lang.classcastexception: lecteur.$proxy0 cannot cast com.sun.jna.library

here source code:

package lecteur;  import java.util.hashmap; import com.sun.jna.library; import com.sun.jna.native; import com.sun.jna.win32.stdcalllibrary;  public class lecteur {  interface nativeinterface extends stdcalllibrary.stdcallcallback { boolean getapierrorstring(string pcerrorstring, int mxlen);  }  public static void main(string[] args) {      hashmap<string, object> namemapping = new hashmap<string, object>();      namemapping.put(library.option_function_mapper, stdcalllibrary.function_mapper);     namemapping.put(library.option_calling_convention, stdcalllibrary.stdcall_convention);     nativeinterface instanceinterface =      (nativeinterface) native.loadlibrary("mvxapi", nativeinterface.class, namemapping);          string pcerrorstring= "aod";     int maxlen = 275;     system.out.println(instanceinterface.getapierrorstring(pcerrorstring, maxlen));    }  } 

i need everybody.

  1. extend stdcalllibrary rather stdcallcallback.

  2. getapierrorstring probably has wrong signature. if function expects able write buffer you're passing it, need use byte[] rather string. passing string gives native code read-only buffer.

edit

  1. you may need use stdcallfunctionmapper if exported functions have form funcname@nn.

    options = new hashmap(); options.put(library.option_function_mapper, new stdcallfunctionmapper()); lib = nativelibrary.loadlibrary("mylib", options);

from jna faq:

my library mapping causes unsatisfiedlinkerror

use dump utility examine names of exported functions make sure match (nm on linux, depends on windows). on windows, if functions have suffix of form "@nn", need pass stdcallfunctionmapper option when initializing library interface.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -