So, normally we typedef to another type or function pointer, but typedef a type to a pointer is strange to me. For example, in winnt.h we got:
typedef void *HANDLE;
typedef PVOID HANDLE;
and PVOID is:
typedef void *PVOID,*LPVOID;
According to that, in the first statement it must be *HANDLE because it’s a pointer to void, while PVOID is already a pointer to void, therefore it needs not to be declare as a pointer.
However, what’s the benefit of typedef a type to a pointer? Isn’t it more confusing?
Usually, modules/Libraries need to maintain some internal state for their proper functioning. This internal state needs to be read/verified on every api that is called for this module/library. So the user of the module needs to pass this information to every api they call. But the library implementor do not want that the users of the library be able to see the contents of this maintained statem, because if they are allowed to, someone might play mischief or make honest mitake of modifying the state, and the results of that might be drastic for the module. To avoid such an scenario the modules mask their state maintiaining variables as a
void*so that now it is opaque(it’s contents are not visible) to users of the module. For benifit of letting the users not being confused about usingvoid *they usually typedef thevoid *asHANDLE, this is for ease of usage for the clients of the module/library.As for the mentioned code:
means wherever you mention
PVOIDhenceforth it will be treated as avoid *type.So in,
is equivalent to:
Because
PVOIDis nothing butvoid *.