tags:

views:

32

answers:

1

Hi all,

I have been attemptng to create a DLL with C/C++ that can be accessed by VB6, and that's right I get error "453 Can't find DLL entry point myFunctionName in myDllName.dll" upon calling the function from a VB6 app. After searching the Web, including this site, I see that I am not alone, and I have tried the various solutions posted but error "453" is unexcapable. This is Not a COMM dll, and I believe that is possible when created via C/C++. In any case, please help, if you can. Please refer to the following simple test case below:

The DLL created as a C/C++ 6.00 Win32 Dynamic-Link Library:

#include <Windows.h>   

// Note that I did try the line below rather than the def file, but to no avail...  
// #pragma comment(linker, "/EXPORT:ibask32=_ibask32@0")

// Function definition   
extern "C" int __declspec(dllexport) __stdcall ibask32()   
{   
    MessageBox(NULL,"String","Sample Code", NULL);   
    return 0L;   
}   

The def file:

LIBRARY "Gpib-32"
EXPORTS   
ibask32

Now for the VB App:

The following is the entire content of the startup Form1, Form_Load

Option Explicit
 Private Sub Form_Load()
  Call ibask
 End Sub

The following is a BAS module file that is added to the project:

Option Explicit

Declare Function ibask32 Lib "Gpib-32.dll" Alias "ibask" () As Long

Sub ibask()

    Call ibask32   ' Note: This is the point of failure

End Sub

Thanks in advance if a workable solution can be provided, Tom

+1  A: 

You are doing everything right as near as I can tell. Verify your assumptions by running Dumpbin.exe /exports on the DLL. That shows the actual name of the exported function, it has to match the Alias in the VB6 declaration.

The only other failure mode I can think of is VB6 loading the wrong DLL. It has to be present in a directory listed on the PATH if you want to use it from the VB6 IDE. Verify by running "where gpib-32.dll" from the command line.

Hans Passant
Thank you Hans, Problem solved... It's now working correctly. Thanks for the Dumpbin /exports lesson that indeed made things much more clear. Where you said above "it has to match the Alias..."set me straight; that is what must be exported from the DLL.Thanks for your prompt response.
@nash, sounds like a helpful answer to me. Please don't forget to mark it as such, check mark next to my post.
Hans Passant
+1 Fantastic answer. @nashth, if you have any more problems check out the 1996 Microsoft advice on writing a C 4.0 DLL that is callable from VB5. They never updated the document, but I should think nearly all the advice is still relevant for C 6.0<->VB6. http://vb.mvps.org/tips/vb5dll.asp
MarkJ
Thanks to Mark for pointing me to MS's vb5dll.asp,in anticipation of what I need next.