使用 JNA 访问包含多个类的 DLL 方法
我是使用 JNA 从 Java 访问 DLL 的新手,所以如果这对每个人来说都是显而易见的,请原谅我!我需要从 DLL 中的类(用 VB 编写)访问方法,并且不能通过仅加载库来做到这一点,因为我看到如何访问其中的类,即 DLL 称为 CDrawControl.dll,但其中的类我需要访问的DLL是DrawCtl。所以我需要获取 DrawCtl 类的实例。 总而言之,如何使用 JNA 访问 DLL 中的这个方法?
即 CDrawControl.DrawCtl.SaveFile()
这可能是我所缺少的非常简单的东西。
public class ReadDLL {
public interface ChemDrawCtl12 extends Library {
CDrawControl INSTANCE = (CDrawControl) Native.loadLibrary(
(Platform.isWindows() ? "CDrawControl" : "CDrawCtl12LinuxPort"),
CDrawControl.class);
void DrawCtl.SaveAs(); // this is wrong but shows what I am trying to do!!
}
I am new to accessing DLLs from Java using JNA,so forgive me if this is obvious to everyone! I need to access methods from a class within a DLL(which was written in VB) and cannot do this by just loading the library as I see how to access a class within it I.e. the DLL is called CDrawControl.dll, but the class within the DLL I need to access is DrawCtl. So I need to get an instance of the DrawCtl class.
So all in all, how to I reach this method in the DLL using JNA?
I.e. CDrawControl.DrawCtl.SaveFile()
It is probably something very simple I am missing.
public class ReadDLL {
public interface ChemDrawCtl12 extends Library {
CDrawControl INSTANCE = (CDrawControl) Native.loadLibrary(
(Platform.isWindows() ? "CDrawControl" : "CDrawCtl12LinuxPort"),
CDrawControl.class);
void DrawCtl.SaveAs(); // this is wrong but shows what I am trying to do!!
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很可能需要使用 COM 包装器,尝试 JACOB 或 com4j。这些项目可以扫描接口定义文件并生成相应的Java对象。
You most likely need to use a COM wrapper, try JACOB or com4j. Those projects can scan an interface definition file and generate corresponding Java objects.