How can I use a DLL with JNA that does not have an interface

南楼画角 提交于 2020-01-13 20:27:30

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/11798088/how-can-i-use-a-dll-with-jna-that-does-not-have-an-interface

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!