在java中导入extranl dll [英] import extranl dll in java

查看:129
本文介绍了在java中导入extranl dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用system.load()导入dll。但是它显示了java.lang.UnsatisfiedLinkError的异常:led_data_send.SendColorTp(IIIILjava / lang / String; IIII)I。

i keep在d drive中的dll。所以我将dll的路径指定为d://LEDBAR.dll

i我在dll中调用函数SendColorTp。



代码如下所示



i tried to import dll using system.load().but it showing an exception of java.lang.UnsatisfiedLinkError: led_data_send.SendColorTp(IIIILjava/lang/String;IIII)I.
i kept dll in d drive.so i specified the path of dll to d://LEDBAR.dll
i am calling a function SendColorTp in dll.

code as shown below

private native int SendColorTp(int Port, int Addr, int Mode, int Delay, String Context, int FontSize, int FontColor, int SignWidth, int SignHeight);

static{
    System.load("D:\\LEDBAR.dll");
}

推荐答案

首先将java源代码编译成类文件(在ide或javac中)。然后在类文件上运行javah程序。这个javah程序将生成函数声明到C / C ++头文件中。使用此标头实现/导出DLL中的函数。

示例:



_package / X.java:

First compile your java source into a class file (inside your ide or with javac). Then run the javah program on the class file. This javah program will generate the function declarations into a C/C++ header file. Use this header to implement/export the functions in your DLL.
Example:

_package/X.java:
package _package;

public class X
{
    public native int func(float f, boolean b);

    public static void main(String[] args)
    {
        System.out.println("Hello World!");
    }
}





我们在_package目录之外运行以下命令:



We run the following commands outside the _package directory:

javac _package/*.java
javah _package.X



运行这些命令后,你会发现一个_package_X.h文件在当前的目录。


After running these commands you will find a _package_X.h file in the current dir.


这篇关于在java中导入extranl dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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