Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Callback typedefs with __stdcall in MSVC

This typedef:

typedef DWORD WINAPI
(* CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, PHKEY, DWORD);

compiles fine in BorlandCpp, however, when I compile it in msvc I have to remove WINAPI (which is just an alias for __stdcall):

typedef DWORD
(* CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, PHKEY, DWORD);

Why is this happening? Can I remove the WINAPI part safely?

Update: I had to remove "WINAPI" form the typedef, otherwise I got

 error C2059: syntax error : '('

for the line.

Can you tell me why Borland could compile it with "WINAPI" while Msvc couldn't?

like image 451
George Avatar asked Aug 18 '09 23:08

George


1 Answers

I believe on VC++ you need to put the calling convention inside the ()'s Here's an example on MSDN of using a calling convention inside a function pointer typedef.

typedef DWORD (WINAPI * CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, PHKEY, DWORD);

This should compile without problem.

like image 71
Michael Avatar answered Oct 05 '22 23:10

Michael