使用JNA从Java调用VB DLL文件的功能 [英] Call a function of VB DLL file from java using JNA

查看:268
本文介绍了使用JNA从Java调用VB DLL文件的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用JNA的新手。我要做的就是使用Java&中的vb DLL文件。从Java调用函数。
我为此创建了一个简单的Java代码。

I am new to using JNA.In all what i want to do is use the vb DLL file in java & call the functions from java. I created a simple java code for this.

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

public class Main
{
    public interface test extends Library
    {
        void fn_Today(int a,int b);
    }

    public static void main(String[] args)
    {
        test INSTANCE = (test) Native.loadLibrary(
            (Platform.isWindows() ? "test" : "test"), test.class);

        int a = 1;
        int b=2;

        INSTANCE .fn_Today(a,b); 
    }
}

当我运行此java程序时,出现以下错误-

When i run this java program i am getting following error-

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up      function 'fn_Today': The specified procedure could not be found.

at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:344)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:324)
at com.sun.jna.Library$Handler.invoke(Library.java:203)
at com.sun.proxy.$Proxy0.fn_Today(Unknown Source)
at mwrobel.jna.Main.main(Main.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)


b
$ b Dll代码为

Dll code is as

Public Function fn_Today(ival As Integer, ival2 As Integer)
Dim ret As Integer
ret = ival + ival2

End Function

我怎么能解决了这个问题?

How can i solved this issue?

我从依赖遍历器获得了以下输出。

i got the following output from dependency walker.

Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing  
export function in a delay-load dependent module.


推荐答案

如果您的VB DLL是C兼容的共享库(如果在其上运行 Dependency Walker ,您会看到格式为XXX @ NNN的标签),那么以下内容应该可以工作

If your VB DLL is a C-compatible shared library (if you run Dependency Walker on it you'll see labels of the form XXX@NNN), then the following should work.

import com.sun.jna.win32.StdCallFunctionMapper;
import com.sun.jna.win32.StdCallLibrary;

public class Main
{
    public interface TestLibrary extends StdCallLibrary
    {
        void fn_Today(int a,int b);
    }

    public static void main(String[] args)
    {
        Map options = new HashMap() {
            { put(Library.OPTION_FUNCTION_MAPPER, new StdCallFunctionMapper()) }
        };
        TestLibrary INSTANCE = (TestLibrary) Native.loadLibrary("test", TestLibrary.class, options);

        // ...
    }
}

这篇关于使用JNA从Java调用VB DLL文件的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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