views:

754

answers:

2

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?

A: 

A function pointer must have information about the calling convention used by the function. If you're pointing to a function that uses the __cdecl calling convention, you must use a __cdecl function pointer. If you're pointing to a function that uses the __stdcall calling convention, you must use a __stdcall function pointer.

Hope this helps.

Eduardo León
+3  A: 

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.

Michael
Thank you, this one works : )
Richard J. Terrell