简体   繁体   中英

How to call a native C DLL from vb6

Ok, so: I HAVE to create an .exe in vb. This .exe has to call a vb dll, and that vb dll has to call a native C dll (still working on that :( ).

The real problem is: I have this C dll which I'm trying to call from the .exe so I can learn how it works to move on. The problem is: everytime I try to call it, it gives me "error 53: file not found". BUT! if I point to another DLL in the same location (a more simple one, without any external includes and shit) it works.

Why? Do I have to include something else in the VB project besides the dll itsels?

@Edit1

I have already created a testing program in C that calls that DLL, and it works just fine.

I managed to make some changes and now I have another question, this is WAY more important. :(

I can call a DLL normally now. The thing is: I created a VB6 exe that calls the DLL in C. The function in C that I have to call is named "FindPIN". That said, the function FindPIN opens a COM port with CreateFile. The ideia is:

(IN VB6) Call FindPIN -> (IN THE C DLL) FindPIN calls CreateFile and saves the Handle from that port -> Return a code (like < 0 for error, yada yada).

When I call FindPIN, it works, but it always return -1. The function:

hSerialComm = Createfile (...);
if (hSerialComm == INVALID_HANDLE_VALUE)
  return -1;

Which means it can't open the COM port! :(

BUT if I try to run a C exe, like:

(IN C.exe) Call FindPIN -> (IN THE C DLL) FindPIN calls CreateFile and saves the Handle from that port -> Return a code (like < 0 for error, yada yada).

It works just fine and the COM port opens! :(

Is there something I have to do in VB6 besides the commom declaration of the function? I'm doing it normally, like

Private Declare Function FindPIN Lib "pin.dll" () As Integer

:( Please, help me!!

Please post the c-declaration of the FindPin function of your dll. I guess your function does not return short but it returns int , is it true?

Then you have to Declare the return-value of the function in VB "As Long" not "As Integer" because

Integer = short = Int16 and Long = int = Int32

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM