1
votes

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"" ?><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

But I receive this error:

enter image description here

I used "Dependency Walker" to list the functions from the dll file: enter image description here

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.

1
This is not a normal DLL, the kind that would have an exported function named GetUnitInfo(). It is a COM library, rundll32.exe is not going to be useful. You forgot to mention the programming tool you use, but in general you want to add a reference to the type library.Hans Passant
Thanks for the reply. I added an edit to my questionNicuVlad
I still have no idea why this question is tagged with [c#]. Look here to get somewhere.Hans Passant
I do not have a complete answer. I think you can import the DLL . Then create an object and that object will have the methods from the dll that you can call direct. I had an example for c# command line but can not find it now. (import as in a line in the code, not importing into your IDE.)William J Bagshaw
Hi William, sounds good. But I don't know where you mean to import itNicuVlad

1 Answers

1
votes

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.