Sign in to follow this  
TEUTON

extern "C" in DLL

Recommended Posts

TEUTON    100
I was learning how to make a DLL. I understood all part but didn't knew why extern "C" was needed before __declspec. I know it reduces name mangling but what is the need for reducing name mangling in case of DLL.

Share this post


Link to post
Share on other sites
_winterdyne_    530
A DLL relies on exported symbols to tell a using application where in the DLL functions are located.

Name mangling trashes the names of these symbols. Extern C specifies that C style naming convention is to be used, which allows the symbols to be used by the calling application.
Basically, without the extern C specification, your DLL's symbols get knackered so it can't be used.

Share this post


Link to post
Share on other sites
TEUTON    100
But extern "C" doesn't removes name mangling...it just reduces name mangling.

Even if we don't use extern "C" can't we use that function...i.e. If we provide

alias(In VB) as the mangled name of function...can't we use it that way??

Share this post


Link to post
Share on other sites
F-Kop    100
Use extern "C" in a DLL if you write it in C++ and you want it to be used with both C and C++ programs. If you don't use extern "C", it can only be used with C++ programs.

Share this post


Link to post
Share on other sites
TEUTON    100
Quote:
Original post by F-Kop
Use extern "C" in a DLL if you write it in C++ and you want it to be used with both C and C++ programs. If you don't use extern "C", it can only be used with C++ programs.


I want to use DLL made in C++ in VB...do we still need to write extern "C" and second question does making DLL in any language is preferred over other?

Share this post


Link to post
Share on other sites
F-Kop    100
If you're gonna use it with VB you should use extern "C". There isn't really a best language for DLLs, but C (or C++ with extern "C") DLLs work with almost everything.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this