我如何将指针引用传递给JNI中的本机方法

时间:2013-01-25 10:59:43

标签: java dll java-native-interface jna

  

可能重复:
  Unable to open the port by calling Native method from ITLSSPProc.dll

我使用功能为ITLSSPProc.dll

的JNI调用OpenSSPComPort(Pointer param);的函数

此指针ref指向 baudrate 和 内存中的 portnumber 这里是我尝试但不能的代码 打开港口。

public class Main {
    public interface ITLSSPProc extends Library {
        ITLSSPProc INSTANCE = (ITLSSPProc) 
            Native.loadLibrary((Platform.isWindows() 
                                    ? "ITLSSPProc" 
                                    : "simpleDLLWindowsPort"), 
                                ITLSSPProc.class);

        int OpenSSPComPort(Pointer param); 
        int CloseSSPComPort(Pointer param);                            
    }

    public static void main(String[] args)throws IOException {
        ITLSSPProc sdll = ITLSSPProc.INSTANCE;
        Memory intMem = new Memory(10);  // allocating space
        intMem.setLong(0,9600);
        intMem.setString(1,"com7");

        Pointer intPointer = intMem.getPointer(0);

        if(sdll.OpenSSPComPort(intMem)==1)
        {
            System.out.println("connected");
        }
        else
        {

        }
    }
}

0 个答案:

没有答案