tags:

views:

137

answers:

1

I am converting a program from C to C++. I have the compiler set to use the __fastcall calling convention by default.

I used to have a declaration line as follows:

INT32 PASCAL graph_window_handler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

Later I have:

wndclass.lpfnWndProc    = graph_window_handler;

This all compiled and worked under C. But under C++ I get all sorts of complaints form the compiler about the second line of code. I guess I need to change the original declaration to something involving WNDPROC, perhaps with a _cdecl thrown in? With or without the INT32? but it seems that every variation I try still gets complained about. What should the declaration look like such that the second line does not get complained about? - cheers.

+4  A: 

According to MSDN documentation it should look like the following:

LRESULT CALLBACK graph_window_handler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

And if you'll check WinUser.h you'll see that WNDPROC typedef'ed as follows:

typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
Kirill V. Lyadvinsky
Thanks for that.I have no idea how/why "LRESULT CALLBACK" is equivalent/castable to "WNDPROC" but heck, its working, so that will do me.
Mick
Thanks for editing in the extra info :-)
Mick