【发布时间】:2017-09-04 22:14:19
【问题描述】:
我正在尝试使用用 Visual Basic 编写的 .dll。我没有写它,所以没有它的源代码。我可以加载它并显示里面的方法,但是在尝试调用一个时得到“java.lang.UnsatisfiedLinkError:错误查找函数”。这是我的代码:
package dlltest;
import com.sun.jna.Library;
import com.sun.jna.Native;
import java.lang.reflect.Method;
import java.util.Collection;
public class DllTest {
public interface TC2005 extends Library {
public boolean TCEnabled();
}
public static void main(String[] args) {
TC2005 tc2005 = (TC2005)Native.loadLibrary("TC2000Dev",TC2005.class);
Method[] methods = tc2005.getClass().getDeclaredMethods();
for (Method method:methods) System.out.println(method);
System.out.println("TCEnabled="+tc2005.TCEnabled());
}
}
这是输出:
public final boolean com.sun.proxy.$Proxy0.TCEnabled()
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'TCEnabled': The specified procedure could not be found.
at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:345)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:325)
at com.sun.jna.Library$Handler.invoke(Library.java:203)
at com.sun.proxy.$Proxy0.TCEnabled(Unknown Source)
at dlltest.DllTest.main(DllTest.java:70)
还有更多功能和输出,但为了清楚起见仅显示一个。
整天无所事事地阅读有关该主题的帖子。一些人谈论编译器修改方法名称,因此需要 FunctionMapper 代码。要获得每个人都说使用 Dependency Walker 的真实方法名称。尝试使用它来加载 .dll 很多错误。还尝试加载使用 .dll 的 .exe,然后在 DW 中运行 Profiler 选项。这锁定了程序。 (没有回应)。
建议?
【问题讨论】:
-
VBA 不是您正在寻找的视觉基础。请更新您的标签
-
您的 java.library.path、系统路径或系统指出的类路径中应该有 TC2000Dev.dll 或 libTC2000Dev.so。
-
是的。这就是库能够加载的原因。
-
遇到完全相同的问题。
-
support@worden.com 没有回复。他们在他们的界面中这样定义这个函数:Public Property Get TCEnabled() As Boolean。我要检查 com4j。看看我能不能有更好的运气。
标签: java dll jna unsatisfiedlinkerror