Question

I am currently working on a project (in C), in which I'm using different win HANDLE (mutex, semaphore, thread, ...). My question is : Is there a way to retrieve the types of kernel object an HANDLE is linked to? Something like : Get_HANDLE_source() or Is_thread_HANDLE() ?

Thank you,

Cheers!

Was it helpful?

Solution

As said NtQueryObject. But It is probably better to use some OO concepts:

struct HandleVtable
    {
    /* function pointer to appropriate implementation */

    };

struct HandleWrapper
    {
    struct HandleVtable *vptr;
    HANDLE handle;
    };

For each type of handle, create a static const HandleVtable and fill it with function pointers. When creating HandleWrappers, set vptr so it points the corresponding vtable, and let all function calls go through that vtable. For this it is best to write a wrapper function that takes a pointer to a HandleWrapper.

Now you will have OOP in C.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top