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.
extend
stdcalllibrary
ratherstdcallcallback
.getapierrorstring
probably has wrong signature. if function expects able write buffer you're passing it, need usebyte[]
ratherstring
. passingstring
gives native code read-only buffer.
edit
you may need use
stdcallfunctionmapper
if exported functions have formfuncname@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
Post a Comment