Certainly.

Name mangling is a feature of the C++ compiler to support the ability to
overload functions. For example, if I create the following two
functions:

int __stdcall MyFineFuction(int a);
int __stdcall MyFineFunction(char * a);

A 'C' compiler would complain, a C++ compiler would not. The reason
would become clear if you create a .MAP file (the so-called "mapfile"),
and you would see that the above two functions have been "renamed" as:

?MyFineFunction@@YGHH@Z  
?MyFineFunction@@YGHPAD@Z

What is interesting is that if you had added __declspec(dllexports) to
this declaration, the two names as listed here would actually be visible
to the outside world. This is how C++ class libraries can be put into
DLLs (just what happens with the Microsoft Foundation Class (MFC)
library. You can use a tool like DEPENDS.EXE (if you have never run it,
you really should. Almost as helpful as ILDASM.EXE!) to look at files
like MFC42.DLL and to see all the beautifully mangled names.

The format of this, by the way, is documented somewhere to help
developers who want to build compatible tools for this. There is also a
de-mangler around somewhere, but I forget the name.

When you understand what this is for, it becomes clear that to a C++
compiler developer, these names aren't mangled - oh no, they are
"decorated" <grin>.

For functions that can be called from VB or C, though, the use of the
extern "C" declarator is the best way to go. In those cases, you
probably don't want to override a function (a feature not found in
either VB or C).

Hope that helps.

My Best,
Paul

Paul Yao
The Paul Yao Company
http://www.paulyao.com
Voice: 425-747-1355

Microsoft eMVP


> -----Original Message-----
> From: Lik Mui [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 20, 2002 11:54 PM
> To: [EMAIL PROTECTED]; Paul Yao
> Subject: Re: PInvoke, WinCE, and CompactFramework
> 
> Thanks Paul for pointing that out.
> 
> Your approach seems to suggest that name mangling is due to the C++
> compiler for C++ symbols but ok for regular C (perhaps for other
languages
> like vb, C#, ...).  Can you provide some more insights on this name
> mangling issue?

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to