使用Java调用.dll函数 [英] Call .dll functions using Java

查看:1261
本文介绍了使用Java调用.dll函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为从".dll"文件中调用方法的客户端编写应用程序.以前是通过".exe" GUI手动执行".dll"文件的,但现在他们希望使该过程自动化.

I need to write an application for a client that calls a method from a ".dll" file. The ".dll" file was previously executed manually from an ".exe" GUI but now they want to automate the process.

我从未使用过.dll文件,因此直到现在我发现的所有内容都是经过一整天研究的结果,我还收到了有关此工具的小文档:

I never worked with .dll files so everything that I found until now is the result of a complete day of research, I also received a small documentation with this tool:

该接口是一个ActiveX DLL,它提供两个功能(GetUnitInfo和SaveResult).

此刻,我只想使用RUNDLL32.exe从Winwdows命令行运行"GetUnitInfo"方法.

In the moment I just want to run the "GetUnitInfo" method from the Winwdows command line using RUNDLL32.exe.

这是"GetUnitInfo"方法的文档: GetUnitInfo的界面如下:

This is the documentation for the "GetUnitInfo" method: The interface for GetUnitInfo is as follows:

Public Function GetUnitInfo( _
ByVal strRequest As String, _
ByRef strUnitInfo As String,
Optional ByVal strStationName As String = "") As Long

示例调用代码可以是:

Dim lRet As Long
    Dim strXML as String
    lRet = GetUnitInfo( _"<?xml version=""1.0"" ?><GetUnitInfo 
    xmlns=""urn:GetUnitInfo-schema"" SerialNumber=""BD3ZZTC8MA"" />",  strXML)

因此,我尝试使用一些虚拟参数运行此方法,因为如果参数不正确,该方法将返回错误.命令:

So I tried to run this method with some dummy parameters because the method returns an error if the parameters are not OK. The command:

RUNDLL32.EXE FFTester.dll, GetUnitInfo test1, test2

但是我收到此错误:

我使用"Dependency Walker"列出了dll文件中的功能:

I used "Dependency Walker" to list the functions from the dll file:

但这是所有功能,通常我希望还会列出"GetUnitInfo".

But this are all the functions, normally I would expected that also "GetUnitInfo" is listed.

有人可以帮忙吗?并非必须使用RUNDLL32.

Can somebody help? It is not mandatory to use RUNDLL32.

以后 我想从用JAVA编写的工具中调用此DLL,我尝试使用JNA,但失败了,所以我想从命令行调用dll函数,因为如果这可行,我可以使用进程生成器来执行命令

Later edit: I want to call this DLL from a tool that is written in JAVA, I tried to use JNA but I failed so I was thinking to call the dll functions from the command line because if this works I can use a process builder to execute the command.

推荐答案

我已解决问题,我将提供解决方案,也许会对其他人有所帮助.

I fixed my problem and I will provide a solution, maybe it will help someone else.

我使用了 com4j 库来生成我的dll的接口.此后,您需要注册您的DLL,否则最有可能您的代码将抛出"ComException",您可以阅读更多

I used com4j library to generate the interfaces for my dll. After this you need to register your DLL otherwise most problely your code will throw an "ComException", you can read more in my second question. To register a DLL:

C:\ Windows \ SysWOW64> regsvr32.exe"32位DLL的DLL路径"

C:\Windows\SysWOW64>regsvr32.exe "path to your DLL" for 32 bit DLL

C:\ Windows \ System32> regsvr32.exe"64位DLL的DLL路径"

C:\Windows\System32>regsvr32.exe "path to your DLL" for 64 bit DLL

另外,根据您的DLL类型(32位还是64位),您需要使用正确的Eclipse/JDK.

Also depending on your DLL type, 32 or 64 bit, you need to use proper Eclipse/JDK.

这篇关于使用Java调用.dll函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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