0
votes

I have a library code which is written in VS 2003 , C++ 7.1

I managed to compile it in VS 2010. Now i need to compile it in VS2003 as well.

Problem is that i can not prevent VS2003 name mangling !

I used __declspec(dllexport) __stdcall before function name and i also put codes in extern "C" block.

I still get mangled function names when i compile it in VS 20003. I dont need a .def file when i use __declspec(dllexport) right?

hee is the code :

extern "C"
{

   void __declspec(dllexport) __stdcall FreeMyObject(MyObjectHandle pObj)
   {
    delete pObj;
   }
}

Also "Callin Convention" is __cdecl (/Gd)

Why i get mangled function names? is there any options i need to set in compiler option?

1
It will be decorated as _FreeMyObject@4, the stdcall decoration. Not the same thing as C++ name mangling. It is not incompatible with C. If you want to rename it then you must use a .def file.Hans Passant
Thanks you, yest it seems its because of stdcall. So compiler behave different in VS2010? because its working fine without a def file. Thanks for the answer by the way :)QProgrammer
It has been this way for a very, very long time. Nothing different in VS2010. The only reasonable guess is that you are building 64-bit code in the VS2010 project. Which doesn't need name decoration, there is only one calling convention. You are not leaving anything else to guess at.Hans Passant
there's no C++ 7.1, only C++98, 03, 11, 14, 17, 20...phuclv

1 Answers

1
votes

The keyword _stdcall, along with _cdecl, _thiscall, and others, are all calling conventions specifying how the compiler handles pushing and popping the arguments and the return value. Functions names made with _stdcall (at least in visual studio) are "decorated" when they are exported. If you want to find the exported name of the function, you can use the visual studio command line function DUMPBIN /EXPORTS "DLL file location". Your function name will probably look something like this: _FreeMyObject@(some number). You could also use a .def file and define the name yourself, but I personally think that is a pain.