Use of extern "C" in dlls

Nov 8, 2011 at 2:13pm
I'm confused about importing and exporting functions with a dll written in C++. Most books and articles and code samples I see use this code before declarations:

extern "C" __declspec(dllexport) //or dllimport

What I understand about the extern part is that it prevents the compiler from name mangling so the dll is compatible with C programs. My question is, is that the only purpose of extern "C"? If I plan to use my dll only with C++ do I really need that part? I ask because when I include it it only raises problems in my code. For one thing if I export a function from a header file using extern "C" then the function won't appear in the VS intellisense dropdown box. I also get a strange linker error when I try to link with the dll about the dll being corrupt. I have no problems if I remove the extern "C" part however.
Nov 8, 2011 at 2:38pm
Yes, the only purpose of the extern "C" command is to prevent name mangling and preserve compatibility with C.
Nov 9, 2011 at 9:05pm
What strange linker errors are you getting? Just using C linkage shouldn't be causing any problems.
Topic archived. No new replies allowed.