News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Valid Handle

Started by msmith, September 12, 2006, 03:17:07 AM

Previous topic - Next topic

msmith

I have seen published tables of valid message numbers where WM_USER starts at $400 etc.

Is there a numerical range in which all valid handles will reside?

Tedd

Between 0 and ffffffffh, inclusive :bdg

Firstly it will depend what type of handle it is -- window? file? memory? device context? .........
When it comes down to it, a handle is just a number indicating an 'object', and the validity of its value is down to the implementation that uses it (the relavent api functions.) So, short answer - no, not really :P
No snowflake in an avalanche feels responsible.

msmith

Tedd,

Quote
Between 0 and ffffffffh, inclusive

Regarding CreateWindowEx MSDN says:
Quote
If the function succeeds, the return value is a handle to the new window.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Regarding CreateFile MSDN says:
Quote
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

windows.inc defines NULL as 0 and INVALID_HANDLE_VALUE as -1.

So your answer is incorrect in at least 2 cases.

Quote
When it comes down to it, a handle is just a number indicating an 'object',

I know what a handle is.

It is possible that the answer to my question (except in the error cases I pointed out) is indeterminate. If so, just say so.

Even if I try creating a multitude of handles using XP, 98, 2000, etc. and get a pattern of what ranges the various types of handles have, I realize that there is no guarantee that it will always remain that way, so I cannot rely on the data.

I would even agree that an application should not "care" what value a handle is as long as it stores that value and uses it appropriately. I am modifying an old application in which it would be usefull to assign a handle entry in a table with an invalid value to indicate a null entry.

In a sense, I have answered my own question in the case of handles returned by CreateWindowEx... a valid handle of 0 will never occur. So a 0 in the table could safely indicate a null entry.

Tedd

Quote from: msmith on September 13, 2006, 12:27:36 AM
It is possible that the answer to my question (except in the error cases I pointed out) is indeterminate. If so, just say so.

Quote from: Tedd on September 12, 2006, 12:00:24 PM
..... just a number ..... the validity.. is down to the implementation ................. So, short answer - no, not really :P

But in most cases 0 and/or -1 are used to indicate invalid handles. This is not necessarily true, but it is common.
No snowflake in an avalanche feels responsible.