Home > Backend Development > C++ > How to Export C DLL Functions without Name Decoration?

How to Export C DLL Functions without Name Decoration?

Mary-Kate Olsen
Release: 2024-11-27 16:07:14
Original
875 people have browsed it

How to Export C   DLL Functions without Name Decoration?

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#@@@@")
Copy after login

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__)
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template