Hi,

I've build a basic dll and a bit of code to call it. My dll is practically empty, the only things really in it are:

Code:
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved) 
{...}

and

extern "C" __declspec(dllexport) int doSomething(void)
{...}
I can load my Dll into my other code using LoadLibrary and GetProcAddress and everything works fine.

Now if I remove the extern "C" from the definition of doSomething then the library loads fine into my other code but the function can't be found when I call GetProcAddress (using the function name "doSomething"). This is clearly a name mangling problem, i.e. by not including extern "C" the name of doSomething get's mangled as it's viewed as a C++ function.

My question is, when would I write a dll where I didn't use extern "C" to export functions? Presumably if I'm loading a dll using this method (i.e. dynamically) then I'll never want to mangle the name else I'll not know what name to call GetProcAddress with. I can see the same problem with loading the dll using another language as well, e.g. C# (especially since name mangling is compiler determined (I think!)).

Any ideas?

Thanks