Why does INVALID_HANDLE_VALUE cast through a LONG_PTR first? To ensure that the proper sign extension happens. Click here to read the article