Re: INVALID_HANDLE_VALUE vs. NULL
- From: "David J. Craig" <SeniorDriversWriter@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 16 May 2005 10:25:23 -0700
Sometimes a HANDLE is not a pointer. In DOS, where the handle with a value
of zero started for MS, it was an index to a table. How a handle is
implemented is sometimes better not known as it might be a case of too much
information. This association of NULL with handle is a bad idea. NULL is a
special value for pointers that means it points to nothing. It may or may
not be zero, but usually it is.
"Doug G" <nospam@xxxxxxxxxxxxx> wrote in message
news:e8ZdYgjWFHA.3220@xxxxxxxxxxxxxxxxxxxxxxx
> "Gary Chanson" <gchanson@xxxxxxxxxxxxxxxxxxxx> wrote in message
> news:%23m4JX9KWFHA.2572@xxxxxxxxxxxxxxxxxxxxxxx
>>
>> "Frank A. Uepping" <trash@xxxxxxxxxxxxxxx> wrote in message
>> news:d654rh$q10$1@xxxxxxxxxxxxxxxxxxxxx
>> > Hello,
>> >
>> > there seems to be two representations for an invalid handle:
>> > INVALID_HANDLE_VALUE and NULL.
>> > Can somebody explain this discrepancy?
>>
>> NULL is a valid value for a file handle (although there are a few
> handle
>> based functions which violate this). For file handles,
> INVALID_HANDLE_VALUE
>> = -1.
>>
>> On the other hand, GDI and user handles can never be NULL and use
>> this
>> value for invalid handles.
>>
>> --
>> -GJC [MS Windows SDK MVP]
>> -Software Consultant (Embedded systems and Real Time Controls)
>> - http://www.mvps.org/ArcaneIncantations/consulting.htm
>> -gchanson@xxxxxxxx
>>
>
> I may be getting my operating systems mixed up, but I thought that almost
> all virtual-memory operating systems set the page at address zero
> (0x000...0) to be an invalid page so that a page fault is generated by any
> type of access to that address. The reason for this is that making a
> reference through a NULL pointer is one of the most common programming
> bugs,
> and by making this page invalid it will cause a crash or other exception
> if
> you make this mistake. I have worked on a few non-VM systems where zero
> was
> a valid address, and that would cause all sorts of system problems when a
> program with NULL in a structure pointer would trash the low memory area
> of
> the system, wiping out interrupt vectors, boot code, or other important
> stuff!
>
> So assuming that a "handle" is used internally as a structure (object)
> pointer, I would be very surprised to find that NULL (0) would be a valid
> value.
>
>
.
- References:
- 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: Doug G
- INVALID_HANDLE_VALUE vs. NULL
- Prev by Date: Re: INVALID_HANDLE_VALUE vs. NULL
- Next by Date: IcmpSendEcho on Windows 2000 client
- Previous by thread: Re: INVALID_HANDLE_VALUE vs. NULL
- Next by thread: Re: INVALID_HANDLE_VALUE vs. NULL
- Index(es):
Relevant Pages
|