java调用 dll,使用Java调用.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.

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:

The interface is an ActiveX DLL which provides two functions (GetUnitInfo and SaveResult).

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

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

Sample calling code can be:

Dim lRet As Long

Dim strXML as String

lRet = GetUnitInfo( _“<?xml version=""1.0"" ?>

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

But I receive this error:

RJkXW.png

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

a27ut.png

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

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

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.

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 "path to your DLL" for 32 bit DLL

Or

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值