0xmax
0xmax

Reputation: 543

Error looking up function in a Borland DLL through JNA

Here is a running example of my DLLService :

import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;

public class DLLService {

public DLLService() throws Exception {
    System.out.println("version = " + version()  + "\n");
    testEvaluate();
}

public void testEvaluate() {
    System.out.println(this.loadFile("file", 1));
    int[] barre = new int[] {0, 1, 2, 3, 4};
    int[] result = new int[]{};
    evaluateParty(barre.length, barre, result, 1);
    System.out.println(result);
}

public int version() {
    return GDLL.INSTANCE.LireNoVersion();
}

public int loadFile(String tslName, int pdwNoSess) {
    return GDLL.INSTANCE.ChargerFichier();
}



public interface GDLL extends StdCallLibrary  {
    GDLL INSTANCE = (GDLL) Native.loadLibrary("tsr32_mini", GDLL.class);

    int LireNoVersion();
    int ChargerFichier();
}
}

There is no problem with the function version() but not with the loadFile(...), I have the exception :

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'EvaluerPartie':

at com.sun.jna.Function.(Function.java:212) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:541) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:518) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:504) at com.sun.jna.Library$Handler.invoke(Library.java:220) at com.sun.proxy.$Proxy0.EvaluerPartie(Unknown Source) at DLLService.evaluateParty(DLLService.java:29) at DLLService.testEvaluate(DLLService.java:16) at DLLService.(DLLService.java:9) at ProblemsIsolator.main(ProblemsIsolator.java:53)

I already search but found nothing that work (changing types, arguments, names, ...). Here is the prototype of the function l: DWORD ChargerFichier (LPSTR chNom, DWORD *pdwNoSess).

EDIT : Same error, even after using a name mapper; it works for the LireVersion only :

public void testFunctionMapper() throws Exception {
        FunctionMapper mapper = StdCallLibrary.FUNCTION_MAPPER;
        NativeLibrary lib = NativeLibrary.getInstance("tsr32_mini");

        Method[] methods = {
                GDLL.class.getMethod("LireNoVersion",
                                        new Class[] { String.class, int.class }),
                GDLL.class.getMethod("ChargerFichier",
                                        new Class[] { String.class, int.class }),
        };

        for (int i=0;i < methods.length;i++) {
            String name = mapper.getFunctionName(lib, methods[i]);
            lib.getFunction(name, StdCallLibrary.STDCALL_CONVENTION).getName();
        }
}

Also, a dependency worker showed me well of the methods.

Upvotes: 3

Views: 1588

Answers (2)

JFPicard
JFPicard

Reputation: 5168

As it seems to works in that link: How do I get a java JNA call to a DLL to get data returned in parameters?, I can see that your definition of ChargerFichier is missing parameters.

Maybe the definition should be something like:

int ChargerFichier(PointerByReference chNom, IntByReference pdwNoSess);

Maybe this link can help you too: http://www.viaboxx.de/code/java-interoperation-with-a-native-dll-using-jna/

Upvotes: 1

technomage
technomage

Reputation: 10069

This is how you'd use the StdCallFunctionMapper:

Map options = new HashMap();
options.put(Library.OPTION_FUNCTION_MAPPER, new StdCallFunctionMapper());
MyLib lib = (MyLib)Native.loadLibrary("tsr32_mini", MyLib.class, options);

Upvotes: 1

Related Questions