C++ – have __stdcall


I am starting doing some directX programming. I am using this tutorial that I have found from the Internet.

I am just wondering why the CALLBACK has been defined as _stdcall and why WINAPI is as well.

I thought __stdcall was used when exporting functions that will be compiled as a dll.

However, as WindowProc and WINAPI will never been exported why are these functions declared as __stdcall?

Many thanks for any suggestions,

// WindowProc function prototype
                            UINT message, 
                            WPARAM wParam, 
                            LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)


Best Solution

__stdcall refers to the calling convention, and doesn't necessarily have to do with exporting functions. Take a look at Wikipedia's article on calling conventions if you want to know more. In brief, the compiler needs to know where to pass the parameters to your function, on the stack or in registers etc.