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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
inprasCommented:
Have U defined UR exported functions in .def file in the dll? if not so add them and try
Regards
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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
SampsonCCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.