Home >Backend Development >C++ >How Do I Control Exported Function Names in C DLLs?
C DLL Exports: Understanding Decorated/Mangled Names
In C , when creating DLLs with exported functions, it's common to encounter decorated or mangled names after compilation. These can be confusing, as they differ from the expected undecorated function names.
Why Decorated Names?
The decoration of function names is a mechanism used by compilers to ensure that function signatures are unique. This is especially important in cases where multiple functions have the same name but different parameters. The decoration includes information about the function's calling convention, parameter types, and other attributes.
Module Definition File vs. "C" Style Exports
Both using a module definition file (.def) and the "C" style of exporting (extern "C" __declspec(dllexport)) can result in decorated names. This is because they both use the underlying Windows PE format, which requires decorated names for exported functions.
Removing the Decorated Name
To remove the decorated name after the "=", you can use the #pragma comment(linker) directive. This allows you to specify the exported function name and the decorated name it resolves to.
For example:
#pragma comment(linker, "/EXPORT:SomeFunction=_SomeFunction@@@23mangledstuff#@@@@")
Alternatively, you can use the following inside the function body to automatically generate the decorated name:
#pragma comment(linker, "/EXPORT:\"" __FUNCTION__ "\"=\"" __FUNCDNAME__ "\"")
Conclusion
Decorated names are an inherent part of the Windows PE format. By using the #pragma comment(linker) directive, you can specify the exported function name and the decorated name it resolves to, allowing you to control how exported functions appear in dumpbin.exe output.
The above is the detailed content of How Do I Control Exported Function Names in C DLLs?. For more information, please follow other related articles on the PHP Chinese website!