Is mangled name used in C# P/Invoke signature declaration?

No, the mangled name is not used in the C# P/Invoke signature declaration. Instead, the ordinal number is used to identify the entry point of a native C++ function in the native C++ DLL. There are a couple of reasons to choose the ordinal number. One is that it is just an integer number, it is short, size of the final .NET assembly is reduced. Two is that the code will look cleaner, not like the mangled name which may be up to hundreds of characters, especially for a function of an instantiated template class. The last is that it is really not a concern to developers since the C# P/Invoke signature shall be generated automatically, it is not meant to be maintained by developers anyway.

The following is an example of declaration of c_str function of the most commonly used native C++ class, std::string.

← Faqs
Translate »