开发者

what is the syntax for a __stdcall name decoration?

开发者 https://www.devze.com 2023-03-25 01:53 出处:网络
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);

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 aski开发者_如何学Gong for ?VB_Create@@YGHPAD@Z name decoration? what standard is this?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消