2013-05-11 85 views
3

我是一个java新手,我试图加载一个delphi dll,并从中调用函数。在java中使用jna加载delphi dll

使用winbinder在PHP已经尝试过,但它似乎是无用的:reloading dll in winbinder (php gui) crashes program

反正我有这个简单的Java代码,我无法弄清楚如何使它发挥作用。互联网上有一些例子,但似乎没有一个适合我。

Dll是32位,所以是我的Windows,JDK和Eclipse。简单功能使用将是GetDllVersion。我真的会赞同任何帮助。

我甚至无法加载它,这里是第一个错误(有以下几个弹出窗口):

enter image description here

下面是代码:

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

public class Main { 

     static { 
     try { 
      System.load("C:/workspace/XmlDownlaoder/xxxxxxxDLL.dll"); 
     } catch (UnsatisfiedLinkError e) { 
      System.err.println("Native code library failed to load.\n" + e); 
      System.exit(1); 
     } 
     } 

     public static void main(String argv[]) 
     { 
     //how to call functions here? - there will be many functions, and final one should generate xml in return 

     } 
    } 

编辑:Native code library failed to load - 这不显示在控制台上。

+0

DLL将提高在异常的DllMain的。这是初始化时间。你可以从另一个环境加载它吗?例如Delphi。或者C++。 – 2013-05-11 23:09:46

+1

忘记关于Java,直到你可以写一个C程序,将加载DLL – 2013-05-12 16:07:31

+0

我有点期待即将到来,我需要听到(阅读)ID :)。感谢名单。我用C++试试我的运气。 – 2013-05-12 19:09:19

回答

0

不要手动加载你的DLL,让JNA为它做出咕噜的工作。

当您搜索Delphi JNA时,有相当多的优秀资源。

解释一些事情,你可能会碰到一些相关的堆栈溢出问题:

+1

这些都不会有帮助。 DLL初始化引发了Delphi异常。此信息的 – 2013-05-11 23:08:45

+0

Thx。任何想法如何处理?因为我是Java新手也许它会更容易成为C++/c#新手:) - 我问becouse我没有经验的DLL或C – 2013-05-12 14:07:13

+1

如果它也无法加载其他环境,那么最好的办法是开始尝试从一个简单的Delphi应用程序加载它,然后使用Delphi来查看加载失败的原因。 – 2013-05-13 07:25:41