SendMessage returning 0 and GetLastError returning 2 (ERROR_FILE_NOT_FOUND
). ERROR_ACCESS_DENIED
is documented but not this. Anyone have any idea what this means?

- 53,861
- 28
- 137
- 147
-
whose SendMessage? What is the API documentation to which you refer? Can you paste some sample code? – Dan Davies Brackett Sep 29 '09 at 18:44
-
The error message is dependent on what message you're sending. What is the message? – Gerald Sep 29 '09 at 18:45
-
Check the value of GetLastError() before you call SendMessage, it's likely that it already have that value, so you're seeing a 'stale' error, not something set by SendMessage itself. – BrendanMcK Jun 14 '12 at 23:09
1 Answers
SendMessage returning 0 does not, and cannot, indicate failure. SendMessage just returns the value returned by the WindowProc which is frequently 0. There is no way to tell - just via the return from SendMessage - if SendMessage could not deliver the message (perhaps because the window is invalid or belongs to a higher integrity level process).
If the message is documented as returning something other than 0, then, again depending on the message, it might be valid to look at GetLastError() to see why the message processing failed.
Also, no OS functions ever clear the last error code, so any value in GetLastError() can be entirely incidental. Calling an API and then calling GetLastError() might mean the error happened in a previous API call, OR that the API called internally did some operation that 'failed' but was handled and the API itself succeeded.

- 34,244
- 12
- 79
- 148
-
Does this basically mean there is no reliable way to test that the API has failed? – Tomáš Zato May 07 '15 at 08:52