使用 JNA 访问包含多个类的 DLL 方法

发布于 2024-12-24 23:19:47 字数 678 浏览 6 评论 0原文

我是使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌入人心 2024-12-31 23:19:47

您很可能需要使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文