Hi Everyone,

I am developing a software that is interfaced with a RFID device. The RFID device manufacturer provides me with a DLL file that contains various functions to communicate with the device. One of the simplest function in the dll file is "CommOpen". This function opens the selected PC serial port.

I have tried my best to get this function executed using VB.net <DLLImport>. But all efforts proves to be unsuccessful. Following exception is encountered

"Unable to load DLL 'Reader.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

Attached herewith is a zip file that holds the code,dll file and the pdf file that shows the details of the functions and their prototypes.

Please let me know the solution to this problem.



You have to copy Reader.dll into bin/debug and bin/release folder, or use absolute path in <DllImport("Reader.dll", EntryPoint:="CommOpen", ExactSpelling:=False, CharSet:=CharSet.Unicode)>

As per your advice, coping the dll file into the folder bin/debug and bin/release did solve the exception that was encontered i.e.

"Unable to load DLL 'Reader.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

But now return value from the function is "-3". Although it should be 0.
Could you please check the code in the attached zip file. Maybe you might figure out the error in code.



Debug.Print(NfcCommOpen(Me.Handle), "1")) passes a handle to form.

The prototype is short NfcCommOpen(HANDLE *hCom, char *com_port)
and parameters:
- hCom-series handle
- com_port, file name of series port
IMO you should pass a "hCom-series handle" as the first parameter, not a handle to form. I guess the function tries to open the port and -3 indicates an error.

I checked if the manufacturer has some online FAQ or help, but I had some troubles understanding the language ;)

The manufacturer gave me the code in Delphi 2005 to access these dll files. The delphi code works perfectly well. Using the same dll, the NfcCommOpen function returns 0 when called in Delphi.
In delphi the first parameter of the above function is passed as THandle.
Can anyone help me find out whats the equivalent of THandle in .Net. Attached herewith is the Delphi code.



THandle is a generic handle in Delphi. So in .NET you pass an IntPtr most likely. But, I'm still pretty sure that you do need to pass a handle to a com-port, not a form handle.

I checked the code. You should convert this part




to VB.NET. I'm not very familiar with Delphi, but THandle is a pointer and PHandle might be a pointer to a pointer(?). Documentation shows that it should be HANDLE *hCom i.e. "pointer to a handle" and the function returns the "pointer to a handle" .

In VB.NET you could try the following

Private pCom As IntPtr
NfcOpenReader(pCom, 3, "")