JAVA调用第三方DLL的简单方法

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!");

}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容