[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Conceptual Patch - Handle wrapper class

From: Stefan Küng <tortoisesvn_at_gmail.com>
Date: Mon, 14 Mar 2011 20:56:20 +0100

On 12.03.2011 15:00, Oto BREZINA wrote:
>>> If no: would be better to use NULL (0) as Invalid handler.
>> not really. Some APIs return INVALID_HANDLE_VALUE in case of an error,
>> so with those we have to check for that value and not 0.
> There is one half on APIs returning NULL and half returns
> INVALID_HANDLE_VALUE in case of error. In any case you have to check the
> other value and set one you choice to be use in "Is INVALID?" check.
>
>>> It may simplify test for invalid handle a bit, also bValid attribute may
>>> be removed from class.
>>> As I understand INVALID_HANDLER_VALUE is for compatibily with win16 API.
>> I don't know about that. AFAIK even current APIs still return
>> INVALID_HANDLE_VALUE instead of 0 for errors. I think this isn't an
>> issue with compatibility but depends on the API, i.e. which dev team is
>> responsible for the API and to which part of the OS it belongs.
> Have examples if WinAPI (one we talk about here) method addes in Win32
> with error value not NULL ?
> I just read some articels about NULL vs. INVALID_HANDLER_VALUE and
> author states that all new (not existing in WIN16) methods are NULL on
> error.

Not really, no. But I've never heard that INVALID_HANDLE_VALUE is for
compatibility with 16-bit windows.

>> If you use CloseHandle() with an invalid handle, an exception is thrown.
>> If you run the app under a debugger, it will catch that exception. With
>> no debugger, nothing will happen because the exception is caught
>> automatically.
>> So we really have to make sure to not call CloseHandle() with invalid
>> handles because the exceptions make debugging a real nightmare.
> That's reason why I tried to use it. Now you have to check docs, what is
> error handle returned and add some code to change it if needed. In your
> case convert NULL to INVALID_HANDLER_VALUE;
> Maybe some function may do a job.
> /** return handle it or INVALID_HANDLER_VALUE if handle seems be invalid
> HANDLE SetNullAsInvalid(HANDLE h) {
> if (h==NULL)
> {
> return INVALID_HANDLER_VALUE;
> }
> return h;
> }
> If fact this solution is more for edge cases that for normal flow.
>> While I usually like helper classes, I don't think this would help with
>> readability. I kind of like to use 'plain' checks for handle values
>> because it's easier to read and also easier to debug.
> If it don't help in readability maybe methods names are not right ...
> Of corse if you work without it for years (and you catch all pittails),
> changing way is not easy.

There's already a CHandle class:
http://msdn.microsoft.com/en-US/library/80w70bhc%28v=VS.100%29.aspx

Stefan

-- 
        ___
   oo  // \\      "De Chelonian Mobile"
  (_,\/ \_/ \     TortoiseSVN
    \ \_/_\_/>    The coolest Interface to (Sub)Version Control
    /_/   \_\     http://tortoisesvn.net
------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=757&dsMessageId=2711481
To unsubscribe from this discussion, e-mail: [dev-unsubscribe_at_tortoisesvn.tigris.org].
Received on 2011-03-14 20:56:29 CET

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.