views:

142

answers:

1

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?

+1  A: 

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.

Chris Becke