GetMessage戻り値のお話
GetMessage function (winuser.h)
BOOL GetMessage(
[out] LPMSG lpMsg,
[in, optional] HWND hWnd,
[in] UINT wMsgFilterMin,
[in] UINT wMsgFilterMax
);
Return value
Type:BOOL
If the function retrieves a message other than
WM_QUIT
, the return value is nonzero.
If the function retrieves theWM_QUIT
message, the return value is zero.
If there is an error, the return value is -1. For example, the function fails ifhWnd
is an invalid window handle orlpMsg
is an invalid pointer. [...]
The Old New Things, Raymond Chen, When will GetMessage return -1?
But don’t worry, the standard message pump is safe. If your parameters are exactly
- a valid pointer to a valid
MSG
structure,- a null window handle,
- no starting message range filter,
- no ending message range filter,
then GetMessage will not fail with -1.
2009年4月頃のQ&A
16bitでもやってみました。Windows3.1ではエラーで-1が返りました。Windows3.0では0が返りました。ということでAPI仕様変更は3.1からで、ドキュメントの変更がおいついていなかったということになりそうです。
When Does GetMessage Return -1? (2010-10-04)
Knowning what we know now, we can see that the return value section of the GetMessage doc page is correct, if only partially. Out of the 5 failure cases over which a user has control, only an invalid, non-null HWND actually returns -1. An invalid message pointer never does, returning 0 on older NT and 1 on 9x Windows, but worse, causing an access violation on new when given a completely wild pointer.