Question

I just created a DLL for my boss in MSVC++2010. I selected "New Win32 DLL" with option "Export symbols", so, everything is completely standard. There are some predefined exports in the new project files, a class, its constructor, a global function and variable with bogus values and a file dllmain.cpp with an APIENTRY function. I changed nothing yet.

Now my boss wants to use the exported things in his VB6 project. He started a VB6 project, did menu "Project" - "Links" (translated from German to English, so it might be somewhat different but I'm sure you know what I mean) and selected a DLL file, just as he says he usually does.

However, VB6 fails to include it, instead showing an error message "could not include DLL file" (no real reason given). The same occurred with a standard new DLL project from Visual C++ 6. My boss thinks it might be because the symbols are not really exported or VB6 needs some special declarations. Does anyone know what the problem is?

Was it helpful?

Solution

Yeah, VB6 doesn't work like that. You need to declare the DLL functions in your VB code somewhat like this:

Private Declare Function WinHelp Lib "user32" Alias "WinHelpA" _
  (ByVal hwnd As Long, ByVal lpHelpFile As String, _
  ByVal wCommand As Long, ByVal dwData As Long) As Long

You would replace "user32" with "MyCPlusPlusDLL.dll" and use the actual method names and signatures etc. from your DLL. Then put the DLL in your /System folder and you should be good to go.

Note: this is assuming that the methods inside your C++ DLL are declared with "__declspec".

OTHER TIPS

I see you already accepted an answer, but this may be of use to you or others. The Universal DLL Function caller, by Paul Caton uses assembly language voodoo to enable VB6 to call different types of DLL functions not normally callable from VB6.

The easiest way to make a DLL in C++ and consume it from VB6 is to use COM.

For a regular DLL, you can't use VB references, but rather need to use the Declare statement. Another option would to be create the DLL as an ActiveX component instead.

If it's not a COM library, you need to export only C function with __stdcall. You might need to create .def file for them (http://msdn.microsoft.com/en-us/library/d91k01sh(VS.80).aspx). Also use dependency walker, e.g. depends.exe to see what functions were exported and with which names.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top