RFC: Should we use the macros in windowsx.h to fix -DSTRICT warni ngs?

Patrik Stridvall ps at leissner.se
Fri Aug 10 11:29:23 CDT 2001

This is not primarily a patch it is a RFC.

I have experimented a bit with fixing the strict
warnings. I have a few patch that I haven't
submitted yet partly because I'm not 100% sure
how all warnings should be fixed.

Anyway, one large class of warnings is the ones cause by the
window messaging functions. Like the one below:
SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);

This one unlike others this one does cause any warning with -DSTRICT
because of the ugly cast, but the principle is the same.

The only good way to fix this kind of problems that I can see is
to use the FORWARD_WM_* macros in include/windowsx.h to write it like:
FORWARD_WM_SETTEXT(lphc->hWndEdit, empty_stringW, SendMessageW);

This works fine because the FORWARD_WM_SETTEXT macro look like this:
#define FORWARD_WM_SETTEXT(hwnd, lpszText, fn) \
    (void)(fn)((hwnd), WM_SETTEXT, 0L, (LPARAM)(LPCTSTR)(lpszText))

Actually I lied this special case will not work fine since
FORWARD_WM_SETTEXT uses TCHAR and friends. But that is not
so important for the general principle. See below.

Anyway, in some meaning the macros only hides the casts, but can casts
really be avoided? We must cast to {W,L}PARAM at some time mustn't we?
And the macros in windowsx.h is not that bad they cast to the correct
type before the cast to {W,L}PARAM. This might help to find some bugs.
Perhaps rewriting to macros as inline functions might help to?

So the question is:
Should we use the FORWARD_WM_* macros to avoid typecasts
(or rather avoid visable typecast) or should we not?
If not how should we fix the problems?

And if we decide to use them, is patches like the one below to
include/windowsx.h that fixes the TCHAR and friend problem acceptable
or should we solve such problems in another way?

PS. Alexandre: Feel free to apply the patch below if you agree.


* include/windowsx.h:
Include files used internally by Wine
can't use the types TCHAR and friends.


Index: wine/include/windowsx.h
RCS file: /home/wine/wine/include/windowsx.h,v
retrieving revision 1.7
diff -u -u -r1.7 windowsx.h
--- wine/include/windowsx.h	2001/01/10 22:42:35	1.7
+++ wine/include/windowsx.h	2001/08/10 12:43:18
@@ -714,17 +714,37 @@
 #define FORWARD_WM_ENABLE(hwnd, fEnable, fn) \
     (void)(fn)((hwnd), WM_ENABLE, (WPARAM)(BOOL)(fEnable), 0L)
+/* void Cls_OnSetTextA(HWND hwnd, LPCSTR lpszText) */
+#define HANDLE_WM_SETTEXTA(hwnd, wParam, lParam, fn) \
+    ((fn)((hwnd), (LPCSTR)(lParam)), 0L)
+#define FORWARD_WM_SETTEXTA(hwnd, lpszText, fn) \
+    (void)(fn)((hwnd), WM_SETTEXT, 0L, (LPARAM)(LPCSTR)(lpszText))
+/* void Cls_OnSetTextW(HWND hwnd, LPCWSTR lpszText) */
+#define HANDLE_WM_SETTEXTW(hwnd, wParam, lParam, fn) \
+    ((fn)((hwnd), (LPCWSTR)(lParam)), 0L)
+#define FORWARD_WM_SETTEXTW(hwnd, lpszText, fn) \
+    (void)(fn)((hwnd), WM_SETTEXT, 0L, (LPARAM)(LPCWSTR)(lpszText))
 /* void Cls_OnSetText(HWND hwnd, LPCTSTR lpszText) */
-#define HANDLE_WM_SETTEXT(hwnd, wParam, lParam, fn) \
-    ((fn)((hwnd), (LPCTSTR)(lParam)), 0L)
-#define FORWARD_WM_SETTEXT(hwnd, lpszText, fn) \
-    (void)(fn)((hwnd), WM_SETTEXT, 0L, (LPARAM)(LPCTSTR)(lpszText))
+/* INT Cls_OnGetTextA(HWND hwnd, int cchTextMax, LPSTR lpszText) */
+#define HANDLE_WM_GETTEXTA(hwnd, wParam, lParam, fn) \
+    (LRESULT)(DWORD)(int)(fn)((hwnd), (int)(wParam), (LPSTR)(lParam))
+#define FORWARD_WM_GETTEXTA(hwnd, cchTextMax, lpszText, fn) \
+    (int)(DWORD)(fn)((hwnd), WM_GETTEXT, (WPARAM)(int)(cchTextMax),
+/* INT Cls_OnGetTextW(HWND hwnd, int cchTextMax, LPWSTR lpszText) */
+#define HANDLE_WM_GETTEXTW(hwnd, wParam, lParam, fn) \
+    (LRESULT)(DWORD)(int)(fn)((hwnd), (int)(wParam), (LPWSTR)(lParam))
+#define FORWARD_WM_GETTEXTW(hwnd, cchTextMax, lpszText, fn) \
+    (int)(DWORD)(fn)((hwnd), WM_GETTEXT, (WPARAM)(int)(cchTextMax),
 /* INT Cls_OnGetText(HWND hwnd, int cchTextMax, LPTSTR lpszText) */
-#define HANDLE_WM_GETTEXT(hwnd, wParam, lParam, fn) \
-    (LRESULT)(DWORD)(int)(fn)((hwnd), (int)(wParam), (LPTSTR)(lParam))
-#define FORWARD_WM_GETTEXT(hwnd, cchTextMax, lpszText, fn) \
-    (int)(DWORD)(fn)((hwnd), WM_GETTEXT, (WPARAM)(int)(cchTextMax),
 /* INT Cls_OnGetTextLength(HWND hwnd) */
 #define HANDLE_WM_GETTEXTLENGTH(hwnd, wParam, lParam, fn) \

More information about the wine-devel mailing list