Jna,动态地从java类卸载Dll [英] Jna, Unload Dll from java class dynamically

查看:760
本文介绍了Jna,动态地从java类卸载Dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经google了一点,但dint找到方法来卸载dll使用JNA,从java类。
我正在使用dll从usb设备传输数据使用这个dll,我必须卸载我的dll从java类,以重新使用我的USB设备与同一个类,而不关闭我的整个程序。
这是我如何使用JNA加载我的dll

  public interface UsbSensor扩展库{

UsbSensor INSTANCE =(UsbSensor)Native.loadLibrary(
(Platform.isWindows()?D:\\UsbDevice.dll:D:\\\UsbDevice.dll),UsbSensor.class );

int SearchDevices();

指针重新启动(String type);
}

  UsbSensor sdll = UsbSensor.INSTANCE; 

Dll被放弃。在这里我如何使用我的功能

  sdll.SearchDevices(); 
sdll.Startacquisition();

现在使用这些函数后,我必须卸载我的dll再次加载dll使用上面的代码。订单重用这些功能。



所以如何动态地卸载dll使用JNA?

解决方案

我有同样的问题,但使用 Native.dispose( )没有帮助。我的问题的解决方案是这个问题和答案。它基本上将本机库的实例设置为null并调用垃圾收集器。


I have googled bit , but dint find way to unload dll using JNA ,from java Class. And as i am using dll to transfer data from usb device using this dll, i have to unload my dll from java class in order to re-use my usb device with same class without closing my whole program. here is how i load my dll using JNA

public interface UsbSensor extends Library {

        UsbSensor INSTANCE = (UsbSensor) Native.loadLibrary(
                (Platform.isWindows() ? "D:\\UsbDevice.dll" : "D:\\UsbDevice.dll"), UsbSensor.class);

        int SearchDevices();

        Pointer Startacquisition(String type);
}

and by

 UsbSensor sdll = UsbSensor.INSTANCE; 

Dll is loded. And here how i use my function

sdll.SearchDevices();
sdll.Startacquisition();

And now after using these function I must have to unload my dll in again load dll using above code. order reuse these function.

So how to unload dll dynamically Using JNA?

解决方案

I had the same issue but using Native.dispose() did not help. The solution to my problem was this question and answer. It basically sets instance of the native library to null and calls the garbage collector.

这篇关于Jna,动态地从java类卸载Dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆