Re: INVALID_HANDLE_VALUE vs. NULL
- From: Pete Gontier <kokorozashi@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 17 May 2005 13:51:33 -0700
On 5/17/05 11:20 AM, in article #62X22wWFHA.3676@xxxxxxxxxxxxxxxxxxxx, "Gary
Chanson" <gchanson@xxxxxxxxxxxxxxxxxxxx> wrote:
>> The INVALID_HANDLE_VALUE, which is -1, is in fact a valid handle, which
>> means "this process". Of course, ReadFile() will fail with this handle,
>> because the object type is wrong, just like ReadFile() will fail on a
>> perfectly valid handle of a mutex, a thread, etc.
>
> Then why did they make INVALID_HANDLE_VALUE -1?
I believe this page has been linked at least twice so far in this thread,
but another link can't hurt (especially since this is not the only reason I
am posting yet again):
http://blogs.msdn.com/oldnewthing/archive/2004/03/02/82639.aspx
>> CloseHandle() does indeed fail when given a bad handle. It will fail on
>> both -1 and 0: -1 cannot be closed, and 0 is just wrong. When CloseHandle()
>> fails, it checks whether a debugger is attached to the process, in which
>> case it raises an exception.
>
> When I try it, I don't see an exception for either -1 or 0.
I haven't been able to make the exception happen either. I may not be
running an appropriate flavor of debugger. However, CloseHandle does fail
when passed 0 and a subsequent call to GetLastError does return
ERROR_INVALID_HANDLE.
.
- References:
- INVALID_HANDLE_VALUE vs. NULL
- From: Frank A. Uepping
- Re: INVALID_HANDLE_VALUE vs. NULL
- From: Arkady Frenkel
- Re: INVALID_HANDLE_VALUE vs. NULL
- From: Frank A. Uepping
- Re: INVALID_HANDLE_VALUE vs. NULL
- From: Gary Chanson
- Re: INVALID_HANDLE_VALUE vs. NULL
- From: qfel
- Re: INVALID_HANDLE_VALUE vs. NULL
- From: Gary Chanson
- Re: INVALID_HANDLE_VALUE vs. NULL
- From: Slava M. Usov
- Re: INVALID_HANDLE_VALUE vs. NULL
- From: Gary Chanson
- INVALID_HANDLE_VALUE vs. NULL
- Prev by Date: DeviceIoControl and IOCTL_DISK_GET_CACHE_INFORMATION
- Next by Date: consistency of format of DevicePath values
- Previous by thread: Re: INVALID_HANDLE_VALUE vs. NULL
- Next by thread: Re: INVALID_HANDLE_VALUE vs. NULL
- Index(es):
Relevant Pages
|