Creating DLL's in Visual C++, for use in VB

I am creating some DLL's in Microsoft's Visual C++ for use in VB.

I can compile and create the DLL's, however, when I try to register them using regsvr32.exe or try to access them in VB using the DECLARE method, the system can't find a DLL entry point.

Do I need to explicitly create this in the VC++ code, or is there a setting I need to use - which I do not know about,
NniolAsked:
Who is Participating?
 
SampsonCConnect With a Mentor Commented:
Here is what you need to do-

In the declaration of the functions, you need to use extern "C" to prevent the compiler from mangling the names of the functions.  For example, the .h file would look something like this-

extern "C"
{
   int A();
}

You neeed to put extern "C" in the definition of the functions like-

extern "C"
{
    int A()
    {
         //Do some work
    }
}

Then you need to create a def file to export the functions from the DLL.  For my example, it would look like-

EXPORTS
    A

Then when you compile the DLL, the function will be exported for use in a VB program.  

On the VB side you'll need some lines like-

Declare Function A Lib "My.dll" () As Long

You only use regsvr32 with DLL's if there are COM objects that you need to register in the DLL.

You should also be able to use __declspec(dllexport) with each function you wish to export instead of the def file.
0
 
Gandalf32Commented:
Normal DLL are not registered with regsvr32. This is only for COM components. To use a regular DLL in Visual Basic, copy it to the program's directory, and declare the functions in a global module.
Remember to declare the functions in the DLL as EXPORT.
0
 
PinTailCommented:
You should note that VB uses _stdcall calling convention for functions in DLLs

Is this a Standard DLL or a DLL that exports some com compliant interface ??

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
inprasCommented:
Have U defined UR exported functions in .def file in the dll? if not so add them and try
Regards
0
 
captainkirkCommented:
I believe, if I'm not mistaken, that you may also need to make sure that your references in VB are updated to include the dll so that VB knows what kind of objects you are using...
0
 
PinTailCommented:
You don't need a DEF file to export functions
0
 
IexpertCommented:
You do need the def file to set theexported names correctly for VB to find them
0
 
MichaelSCommented:
There is an alternative for def file:

extern "C"
0
All Courses

From novice to tech pro — start learning today.