C DLL Decorated Name Exportation
You have noticed that when exporting function names from a C DLL using either a Module Definition (.def) file or the C-style extern "C" __declspec(dllexport) syntax, the exported function names are decorated with additional information. This is due to C name mangling, a process that encodes information about function parameters and types into the function name.
To remove this extra decoration, you can use the #pragma comment compiler directive. By adding the following line to your code:
#pragma comment(linker, "/EXPORT:SomeFunction=_SomeFunction@@@23mangledstuff#@@@@")
You can specify the decorated name for the function you want to export. In this case, "SomeFunction@@@23mangledstuff#@@@@" is the decorated name for the function "SomeFunction."
Alternatively, you can use the following pragma to automatically generate the decorated name:
#pragma comment(linker, "/EXPORT:\"" __FUNCTION__ ""= "" __FUNCDNAME__)
This pragma uses the FUNCTION and FUNCDNAME macros to insert the function name and its decorated version into the pragma.
Using either of these pragmas will result in the following output when viewed with dumpbin.exe:
SomeFunction
This method allows you to retain the functionality of exported functions while removing the unwanted decoration in the function names.
The above is the detailed content of How to Export C DLL Functions without Name Decoration?. For more information, please follow other related articles on the PHP Chinese website!