JNA回调问题

时间:2015-11-09 08:38:49

标签: java jna

我想调用一个DLL文件,已成功创建了与JNA studio的接口。我在调用必要的方法时遇到了问题。

请参阅下面的界面。

public interface MME9000Library extends Library {

    public static final String JNA_LIBRARY_NAME =LibraryExtractor.getLibraryPath(" MME9000", true, TP9000Library.class);  

    public static final NativeLibrary JNA_NATIVE_LIB NativeLibrary.getInstance(TP9000Library.JNA_LIBRARY_NAME,      MangledFunctionMapper.DEFAULT_OPTIONS);    

    public static final VLibrary INSTANCE = (MME9000Library)Native.loadLibrary(TP9000Library.JNA_LIBRARY_NAME,       MME9000Library.class, MangledFunctionMapper.DEFAULT_OPTIONS);     

    public static final int TP_TRUE = (int)-1;
    public static final int TP_NOT_SUPPORTED_IMAGE = (int)-4;
    public static final int TP_FALSE = (int)-2;
    public static final int TP_DLL_NOT_LOADED = (int)-3;

    public interface pfnSetLogPathFile extends StdCallCallback {
        int apply(Pointer pLogFile);
    };
    public interface pfnGetConnectedDevices extends StdCallCallback {
        int apply(int dwDevice, IntByReference pdwCount);
    };

    public static class LPRECT extends PointerType {
        public LPRECT(Pointer address) {
            super(address);
        }
        public LPRECT() {
            super();
        }
    };
    public static class LPBYTE extends PointerType {
        public LPBYTE(Pointer address) {
            super(address);
        }
        public LPBYTE() {
            super();
        }
    };
    public static class HANDLE extends PointerType {
        public HANDLE(Pointer address) {
            super(address);
        }
        public HANDLE() {
            super();
        }
    };
    public static class LPWSTR extends PointerType {
        public LPWSTR(Pointer address) {
            super(address);
        }
        public LPWSTR() {
            super();
        }
    };

    public static class LPDWORD extends PointerType {
        public LPDWORD(Pointer address) {
            super(address);
        }
        public LPDWORD() {
            super();
        }
    };

}

例如,如果我想调用pfnGetConnectedDevices接口(虽然它是C ++头文件中的方法),我该怎么做呢?

2 个答案:

答案 0 :(得分:0)

如果你有一个以函数指针作为参数的函数,那么你可以这样做:

     RoutingCode = (string)root.Element(ns + "Params")
           .Element(ns2 + "Events")
           .Attribute("Code")

答案 1 :(得分:0)

pfnListDevices dvList = new pfnListDevices(){

    @Override
    public int apply(IntByReference pArg1, Pointer pArg2, int pArg3){
        return pArg1.getValue();
    }
};
System.out.println("list device is "+dvList.apply(pdwCount, Pointer.NULL,  0x01000000));