Search code examples
ccalling-conventionname-decoration

what is the syntax for a __stdcall name decoration?


I have a program that calls a set of function as follows:

int _stdcall VB_Create(char*);
int _stdcall VB_Open(unsigned int, unsigned int, unsigned int, unsigned int);
...
...

If there is a mismatch in the name decoration, the linker shows an error like this:

error LNK2019: unresolved external symbol "int __stdcall VB_Create(char *)" (?VB_Create@@YGHPAD@Z) .....

My understanding is that _stdcall syntax is an '_' + 'name of the function' + '@' + 'number of arguments * 4'.

So, why the linker is asking for ?VB_Create@@YGHPAD@Z name decoration? what standard is this?


Solution

  • This is Visual C++ name mangling (I don't know that there is an official page on MSDN to describe the encoding; I could not find one).

    C++ functions need more than just their name encoded into the symbol that ends up in the binary: those symbols need to be unique, but C++ function names need not be unique. Among other reasons, C++ functions can be overloaded, you can have functions with the same name in different namespaces, and you have to be able to handle member functions.

    A compiler uses a compact encoding scheme, like this one, so that functions can be uniquely identiifed.