Can I use void* instead of LPVOID in C?
Or LPVOID perform some special functionality than void*.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no
LPVOIDtype in C, it’s a Windows thing.And the reason those sort of things exists is so that the underlying types can change from release to release without affecting your source code.
For example, let’s say early versions of Microsoft’s C compiler had a 16-bit
intand a 32-bitlong. They could simply use:and, voila, you have your 32-bit integer type.
Now let’s go forward a few years to a time where Microsoft C uses a 32-bit
intand a 64-bitlong. In order to still have your source code function correctly, they simply change thetypedefline to read:This is in contrast to what you’d have to do if you were using
longfor your 32-bit integer types. You’d have to go through all your source code and ensure that you changed your own definitions.It’s much cleaner from a compatibility viewpoint (compatibility between different versions of Windows) to use Microsoft’s data types.
In answer to your specific question, it’s probably okay to use
void*instead ofLPVOIDprovided the definition ofLPVOIDis not expected to change.But I wouldn’t, just in case. You never know if Microsoft may introduce some different way of handling generic pointers in future that would change the definition of
LPVOID. You don’t really lose anything by using Microsoft’s type but you could be required to do some work in future if they change the definition and you’ve decided to use the underlying type.You may not think pointers would be immune to this sort of change but, in the original 8088 days when Windows was created, there were all sorts of weirdness with pointers and memory models (tiny, small, large, huge et al) which allowed pointers to be of varying sizes even within the same environment.