Building DLL in VC++

How can I make DLLs in VC++ to use them in VB?
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.

Its easy

File->New->Projects:: Win32 Dynamiclink Library->Enter Name & Ok->A Dll that exports some symbols->Finish

Your dll is ready.

Now you can remove the class from that and add
extern "C" before all exported functions

You are there.

You may also considering createing COM Dll using ATL, using that will be straight forward.

As far as I know, VB doesn't support the __cdecl calling convention (I may be wrong). AFAIK, the default calling convention in VB is __stdcall.

__cdecl is the default calling convention in C/C++ and it requires the caller to reset the stack after the function returns.
__stdcall, on the other hand, guarantees that the called function will clear the stack before returning (i.e. caller doesn’t have to do anything after the function returns).

If you declare your exported functions like so:

extern "C" __declspec(dllexport) int DoSomething(int param1, int param2);

you will be exporting "DoSomething" with the __cdecl calling convention. You may have problems if you try to call this function from VB.

If you declare your exported functions like so:

extern "C" __declspec(dllexport) int __stdcall DoSomething(int param1, int param2);

you will be exporting "_DoSomething@8" with the __stdcall calling convention. You should be able to call the function successfully from VB (and any other programming language – e.g. Delphi), but the name is not very 'user-friendly'.

To have the best of both worlds, export the function as __stdcall and do the following in your DLL's .def file:


This will basically create a "DoSomething" alias for the "_DoSomething@8" __stdcall function you’re exporting.


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
Check out these websites. I had a similar project and these sites helped a lot.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

rcarlan, summed it up as succinctly as possible!

Here's a pretty good and detailed tutorial regarding VC++ DLL's and using them in VB

How are you travelling on your DLL?

I believe I've answered the question.

Another respondent, topdog770, acknowledged my answer and provided additional information in a form of a link to a website containing a tutorial on the topic.

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

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.