If you create a type that is used, you can include some kind of identification information as part of the type, which will help you exclude some void pointers as being not related to the type you are looking for. Although you will be likely to have the same data or signature in some random memory area as you would, at least you would know when something was not the type you were looking for.
This approach will require that the structure be initialized so that the signature elements used to determine if the memory area is invalid are initialized with the signature value.
Example:
typedef struct { ULONG ulSignature1;
This is a kind of rough approach, but it can help. Naturally, using a macro like IS_MY_STRUCT() , where the argument is used twice, can be problematic if the argument has a side effect, so you need to be careful with something like IS_MY_STRUCT(xStruct++) , where xStruct is a pointer to MySignedStruct .
source share