如何使用没有接口的JNA的DLL [英] How can I use a DLL with JNA that does not have an interface
问题描述
我不想使用JNI
我正在尝试从 pcshll32.dll ,从个人通信使用其HLLAPI。
我确实设法使Python与Python几乎没有任何问题,在网络上找到很多文档和食谱真的很容易。
现在我意外发现了JNA,我遇到了很多麻烦。我几乎找不到关于它的信息,特别是当我试图访问非标准的DLL。
从我的理解我需要编写一个pcshll32.class,这将是界面 - 很像User32.class,似乎是一个界面(或者也许我应该调用这个代理...)到User32.dll。
嗯,这就是我认为在阅读这个。
所以...如何导入外部DLL?可能吗?我需要编写接口/代理?那里有样品吗?
你应该这样做:
public interface PcShll32 extends StdCallLibrary {// StdCallLibrary for Windows函数
PcShll32 INSTANCE =(PcShll32)Native.loadLibrary(
pcshll32,PcShll32.class,W32APIOptions .DEFAULT_OPTIONS); //选项适用于Win32API
//您的方法
}
当然,你必须为JNA提供这个外部库。
对我而言,最好的解释是源代码
After spending a lot of time learning Python to implement a series of DLL based function into Java via Jython - I forgot to read Jython's documentation, and the lack of ctypes support rendered most of my code useless.
I didn't want to use JNI
I'm trying to access some functions from a pcshll32.dll, from Personal Communications using its HLLAPI.
I did manage to make it work with Python with almost no problems, it was really easy to find a lot of documentation and recipes on the web.
Now I discovered by accident the JNA, and I'm having a LOT of trouble with it. I can barely find information about it, specially when I'm trying to access non-standard DLLs.
From what I understand I need to write a pcshll32.class that will be the interface - much like the User32.class that seems to be an interface (or maybe I should call this a proxy...) to the User32.dll.
Well, that's what I think it's happening after reading this.
So... How can I import an external DLL? Is it possible? Do I need to write the interface/proxy? Are there any samples out there?
You should do it like this:
public interface PcShll32 extends StdCallLibrary { //StdCallLibrary is for Windows functions
PcShll32 INSTANCE = (PcShll32) Native.loadLibrary(
"pcshll32", PcShll32.class, W32APIOptions.DEFAULT_OPTIONS); //Options are for Win32API
// your methods
}
Of course you must provide this external library for JNA.
For me the best explanation is the source code
这篇关于如何使用没有接口的JNA的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!