>when i have a HANDLE, how can i know its type?
A handle is an opaque "cookie". I don't think the question is
meaningful : it doesn't have a "type" - it's only meaningful to the
API(s) that you're using it with.
I guess Le asked a good question.
suppose I did this:
h1 = CreateEvent(...) , h2 = CreateFile(...) , h3 = FindFirstFile() , hN =
....(...)
Now I want to have a function like: handleType(HANDLE h)
so when I call it as:
handleType(h1) -> output is: 'h1' is a handle to an event object
handleType(h2) -> h2 is a handle to a file object
handleType(h3) -> h3 is a handle to findfirst opaque data....
I guess the type can be extracted from inside the NT Object manager ...don't
know yet how.
Regards,
Elias
"Bob Moore" <bo...@mvps.org> wrote in message
news:ekrdfv8hp7n7uhrg4...@4ax.com...
As far as I know, there's no direct way to do that. There's a WINAPI call
'GetHandleInformation' but that won't give you much information. For
file-handles, there's a 'GetFileType' API but that obviously works only for
file handles. One solution I think would be to create a function wich tries
a variaty of API calls and the one that returns something useful identifies
the handle type. Something like this:
#define TYPE_UNKNOWN 0
#define TYPE_FILE 1
#define TYPE_PROCESS 2
#define TYPE_THREAD 3
DWORD GetHandleType(HANDLE aHandle) {
DWORD RetVal;
RetVal = GetFileType(aHandle);
if (RetVal != FILE_TYPE_UNKNOWN) return TYPE_FILE;
RetVal = GetPorcessId(aHandle);
if (RetVal != 0) return TYPE_PROCESS;
RetVal = GetThreadId(aHandle);
if (RetVal != 0) return TYPE_THREAD;
....
....
return TYPE_UNKNOWN;
}
--
Andras Tantos, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.