首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Java访问第三方DLL

使用Java访问第三方DLL
EN

Stack Overflow用户
提问于 2015-08-03 09:12:53
回答 1查看 609关注 0票数 1

我正在尝试为科研设备编写一个Java程序,它使用国家仪器驱动程序(DLL),这些驱动程序是用C编写的。目前我对这些DLL一无所知。如果需要,我可以通过我的客户端联系NI以获取详细信息。

我的C/C++技能是古老的,所以我倾向于避免任何需要编写C/C++代码的事情。

寻找建议,包括给我指点教程。我的Java技能非常优秀,目前只是我的C/C++已经有十年历史了。

EN

回答 1

Stack Overflow用户

发布于 2015-08-03 19:44:47

在您的情况下,最简单的选择可能是JNA

下面是一个简单的Hello World example,它向您展示了映射C库的printf函数所涉及的内容:

代码语言:javascript
运行
复制
package com.sun.jna.examples;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/** Simple example of JNA interface mapping and usage. */
public class HelloWorld {

    // This is the simplest way of mapping, which supports extensive
    // customization and mapping of Java to native types.

    public interface CLibrary extends Library {
        CLibrary INSTANCE = (CLibrary)
            Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),
                               CLibrary.class);

        void printf(String format, Object... args);
    }

    // And this is how you use it
    public static void main(String[] args) {
        CLibrary.INSTANCE.printf("Hello, World\n");
        for (int i=0;i < args.length;i++) {
            CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
        }
    }
}

JNA的JavaDocgithub project包含大量用例的示例和教程。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31778178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档