what is the syntax for a __stdcall name decoration?

1k Views Asked by At

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?

2

There are 2 best solutions below

1
On BEST ANSWER

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.

4
On

James already said it: it is a name mangling issue. Put a

#ifdef __cplusplus
extern "C" {
#endif

before and a

#ifdef __cplusplus
}
#endif

after the function declarations. That will turn off C++ name mangling. FWIW, __stdcall has nothing to do with this, although it is required for VB, IIRC.