c - Is it a mistake to check a `HWND` against `INVALID_HANDLE_VALUE`? -


There was a small debate with me with a fellow programmer. He uses the following idiom in his code:

  HWWWWW = some function white writers a wando (); If (hWnd! = NULL & hWnd! = INVALID_HANDLE_VALUE) {// All good} Other {// error}   

I told him that in my opinion this is a wrong view, as There is nothing with the definition hwnd type INVALID_HANDLE_VALUE , but it is certain that this is a good code, because a valid handle is never equal to INVALID_HANDLE_VALUE Maybe

So, is this acceptable and correct idiom? Comparing INVALID_HANDLE_VALUE against

hwnd For this it is a mistake. However, it is not a mistake in practice that will harm you.

Only hwnd is reserved as valid CreateWindowEx as NULL . Now, this is an implementation description that INVALID_HANDLE_VALUE can not be a valid HWND , but this is only the implementation details. The function that manages the window, CreateWindowEx , uses NULL to indicate the failure

If you use your argument with your affiliate If you want to win, then I recommend that you look in SomeFunctionWhichReturnsAWindow and find out which Win32 API is called to produce HWND . Then consult the documentation. This will show you that the NULL reserve has an invalid value.

For clarity, you must test the code against NULL

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -