Jump to content
  • Advertisement
Sign in to follow this  
TEUTON

extern "C" in DLL

This topic is 4497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!