Patrik Stridvall ps@leissner.se writes:
We can just do it like: #ifdef __GNUC__ extern inline void FORWARD_WM_COMMAND(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify, WNDPROC fn) { fn(hwnd, WM_COMMAND, MAKEWPARAM(id, codeNotify), (LPARAM) hwnd); } #else #define FORWARD_WM_COMMAND(hwnd, id, hwndCtl, codeNotify, fn) \ (void)(fn)((hwnd), WM_COMMAND, MAKEWPARAM((UINT)(id),(UINT)(codeNotify)), (LPARAM)(HWND)(hwndCtl)) #endif
if you wish. And if you are worried about preprocessor abusing Winelib application we could do #if defined(__GNUC__) && defined(__WINE__) instead or use some kind of macro wrap around protection of the kind that I proposed that you didn't like.
If you want to wrap WM_COMMAND, do something like:
inline void send_wm_command(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { SendMessageW(hwnd, WM_COMMAND, MAKEWPARAM(id, codeNotify), (LPARAM)hwndCtl); }
This is a normal function, doing a normal SendMessage call, and it's perfectly all right with me. And if you want to do a PostMessage then write a separate post_wm_command() function. Of course this is not a standard Windows API so you cannot put it in the standard header files; but you can have it in some dll private headers, or even directly in the C files that need it.
To sum it up:
- The FORWARD_* API and the HANDLE_* API really are normal functions not macros (preprocessor abuses). The fact Micrsoft implemented them as macros because of lack of compiler support for inline functions or because of incompetence is irrelevant, we can do it right in a 100% compatible way.
No we can't; SendMessage and PostMessage don't have the same prototype, so the preprocessor abuse is necessary to avoid warnings.