Calling C++ dlls in VB

Are there any specific points to take note of when calling C++ dll functions 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.

Some points here
1.when U R passing a string C++ dll expect always null characters in the end so send a string with null characters appended usualy vb doesnot have a null terminated string.
2. Be aware of what the dll function's parameter expects UR ByRef and ByVal are to taken care
Is your C++ Dll is an COM DLL which supports compatible Data types.
manx, if you ask a specific question, perhaps you'll get a useful answer...

What is it you wish to know?
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

From: MSDN:

This is all about decoration... (which you overcome anyways if your inside VS6)
The following is from that MSDN page:

Note   A very good discussion (with example code) of calling a C DLL from Visual Basic can be found in the file VB4DLL.TXT in the VB directory.

Hope this helps.


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
manxAuthor Commented:
The VB4DLL.txt file was very helpful.

A more specific question of sorts.
When I declare the C++ dll and link it to the VB module as follows :

In the C++ dll
__declspec(dllexport) void      StartHTML();

In the VB module
Private Declare Function StartHTML Lib "CGI1" ()

I get a "file not found CGI1" message from the VB compiler.

The file is in the project directory.
Are there any include statements, compiler options etc to include ?

Thanks for all the help so far


I saw a comment about that: it's related with name decoration.
On C you only need (almost) the C function.
In C++ the compiler adds more (+arg_type, ...) to the name so you may not be able to say only "StartHtml" from CGI1.DLL.

Check documentation or ask to mflam.
I didn't realize you were still having problems...

I can prepare and send you an example if you'd like...

My email address is
   One more point I think of is the function in dll which u wish to call from VB must have stdcall calling convention.

All the best

manxAuthor Commented:
Thanks A lot for all the advice.

Finally managed to get the problem solved.


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.