Java调用第三方dll文件的使用方法 System.load()或System.loadLibrary()
package sos;
public class HidCtrlCall {
static {
//java Build Path -> Native library location: 增加HIDCtrl.dll所在目录
//System.loadLibrary("HIDCtrl");
//载入需要调用的dll
System.load("D:\\HIDCtrl.dll");
}
//用native关键字修饰将被其它语言实现的方法
//dll文件中对应的函数声明
public native int GetCtrlCount();
public native void PowerOn1();
public native void PowerOff1();
public native void PowerOn2();
public native void PowerOff2();
public native void PowerOn3();
public native void PowerOff3();
public native void PowerOn4();
public native void PowerOff4();
public static void startAlarm(){
System.out.println(System.getProperty("java.library.path"));
HidCtrlCall hw =new HidCtrlCall();
hw.PowerOn1();//开
}
public static void endAlarm(){
System.out.println(System.getProperty("java.library.path"));
HidCtrlCall hw =new HidCtrlCall();
hw.PowerOff1();//关
}
public static void main(String[] args) {
System.out.println(System.getProperty("java.library.path"));
// TODO Auto-generated method stub
HidCtrlCall hw =new HidCtrlCall();
//本地方法的调用
hw.PowerOn1();//开
try{
Thread thread =Thread.currentThread();
thread.sleep(1);//暂停2秒后程序继续执行
}catch (InterruptedException e) {
e.printStackTrace();
}
hw.PowerOff1();//关
System.out.println("Test OK!");
}
}