使用JNA访问包含多个类的DLL方法 [英] Accessing DLL methods with contain mulitple classes using JNA

查看:605
本文介绍了使用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(); //这是错误的,但显示我正在努力做什么!
}


解决方案

您最有可能需要使用一个COM包装,尝试JACOB或com4j。这些项目可以扫描接口定义文件并生成相应的Java对象。


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!!
}

解决方案

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.

这篇关于使用JNA访问包含多个类的DLL方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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