Immutable C ++ DLL Function Names

Possible duplicate:
How to stop the export process of my exported DLL function?

I have a dll written in C ++. The names of exported functions must be inconsistent. For example, int MyFunc( int Param1, int Param2 ); an external application should appear that tries to call the library function just like MyFunc . However, when I look at it using Dependency Walker, it looks like _MyFunc@8 . This is how I declared it in C ++:

 extern "C" __declspec(dllexport) int WINAPI MyFunc( int Param1, int Param2 ); 

I thought extern "C" would do the trick. How can I get rid of magic? Thanks.

+7
source share
5 answers

Ways to get rid of mangling: (assuming MSVC is a build environment)

Export via .DEF file.

Export as extern "C" to use the __cdecl calling convention. __stdcall adds _ and produces exported @on dll functions, even when extern "C" is used.

 extern "C" __declspec(dllexport) int __cdecl MyFunc(int Param1, int Param2); 

Export using the #pragma directive. You need to pass a completely distorted name on the other side of this. __FUNCDNAME__ is a useful directive to add a macro to a function to list its decorated name,

 #pragma comment(linker, "/EXPORT: MyFunc=_MyFunc@8 "); 
+8
source

The underlined underscore and @8 not associated with the C ++ language name, but rather denote the stdcall calling convention, as is usual with dllexport.

+3
source

Perhaps this is due to the fact that you did not put extern "C" declspec in the function definition, you only put it in the declaration.

+2
source

In the header ( .h ), define it as:

 extern "C" { __declspec(dllexport) int __stdcall MyFunc( int Param1, int Param2 ); } 

Then, when implementing the ( .cpp ) function:

 extern "C" { __declspec(dllexport) int __stdcall MyFunc( int Param1, int Param2 ) { // ... code ... } } 
0
source

Gnu systems have C ++ filter

0
source

All Articles