문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top