Re: INVALID_HANDLE_VALUE vs. NULL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
>
>


.



Relevant Pages

  • Re: (part 10) More Schildt-like errors in Dicky Heathens book
    ... like mallocif mallocreturns a non-NULL pointer. ... If one is using a debugging malloc which checks that all accesses are ... when sz is zero, it gives the debugging allocator an opportunity to ...
    (comp.lang.c)
  • Re: Triplet 630APL meter movement adjustment
    ... was the same whether the meter was standind up or laying down. ... mechanical zero with the unit in the vertical position and took a ... There are three weights on the bottom of the meter pointer; ...
    (sci.electronics.repair)
  • Re: INVALID_HANDLE_VALUE vs. NULL
    ... Sometimes a HANDLE is not a pointer. ... of zero started for MS, it was an index to a table. ... value for invalid handles. ... program with NULL in a structure pointer would trash the low memory area ...
    (microsoft.public.win32.programmer.kernel)
  • Re: (MS-)DOS PC on a microcontroller??
    ... memory block of zero bytes. ... The pointer returned if the ... Each such allocation shall yield a pointer to ... support malloc/calloc requests for 0 bytes and whether or not the ...
    (comp.arch.embedded)
  • Re: Apple III Business BASIC Invokables
    ... I'm using Apple II Pascal 1.3 to assemble to a Pascal object module, then transfer to a physical /// disk... ... It pulls this off with extra hardware to snoop zero page address read/writes used by indirect indexed addressing mode instructions. ... When you get a 16 bit pointer to a buffer, it appears that you have to determine if it is an absolute pointer to somewhere in the current 64K, or an indirect pointer that has been already set up in the zero page/X-byte page. ...
    (comp.sys.apple2.programmer)