Give a void * variable as input (can only point to a process or thread), I’d like to first determine its type and then convert it to that type.
How should I do that in C++? I know it’s a dumb question, but I’ve never done C/C++ before and can’t think C/C++ way yet.
EDIT: I need to achieve this on both Linux and Windows.
You can’t. Pointers carry two pieces of information: the location in memory to where they point and the type of the pointed object. With a
void *this last information is omitted, and there’s no way to reconstruct what type it pointed to. So, you need to carry along this pointer another value that specifies what it actually points to (you can use e.g. anenum).The only facility somehow related to this task in C++ is RTTI, but it works only on pointers to polymorphic classes (RTTI usually exploits the vtable of the object to store additional information about the dynamic type of the pointer, but the vtable can be accessed and correctly interpreted only if it is known that the object belongs to a particular polymorphic class hierarchy).
Well, this is a completely different thing… if you need to pass around your PID/TID inside a
void *you could simply create astructor something like that with a member for the ID and one to store if such ID is a PID or a TID.