walterwkh
asked on
LPVOID conversion
How to convert a LPVOID variable to a string ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In C++ you should use reinterpret_cast<>() as it is safer than C-style casting.
http://msdn2.microsoft.com/en-us/library/e0w9f63b(VS.80).aspx
Note, then you convert to a pointer of a different type the only safe thing you can do with that pointer is convert it back! Anything else is, at best, non-portable.
All styles of casting are discussed here...
http://msdn2.microsoft.com/en-us/library/x9wzb5es(VS.80).aspx
I hope this help.
-Rx.
http://msdn2.microsoft.com/en-us/library/e0w9f63b(VS.80).aspx
Note, then you convert to a pointer of a different type the only safe thing you can do with that pointer is convert it back! Anything else is, at best, non-portable.
All styles of casting are discussed here...
http://msdn2.microsoft.com/en-us/library/x9wzb5es(VS.80).aspx
I hope this help.
-Rx.
It depends on what the LPVOID addresses and what kind of string you mean.
If the LPVOID points to some kind of string, you can convert it to a pointer to that kind of string with a cast, as evilrix showed. A static-cast will work as well as a reinterpret-cast. If you want a different kind of string, you will have to construct a new string from what the pointer addresses. This will also require a cast to turn the LPVOID into something you can use.
For example, if the LPVOID points to a C-style null-terminated string and you want a std::string, you can do this:
std::string exvoid(<static-cast>(const char *) lpVoid);
If the LPVOID points to some kind of string, you can convert it to a pointer to that kind of string with a cast, as evilrix showed. A static-cast will work as well as a reinterpret-cast. If you want a different kind of string, you will have to construct a new string from what the pointer addresses. This will also require a cast to turn the LPVOID into something you can use.
For example, if the LPVOID points to a C-style null-terminated string and you want a std::string, you can do this:
std::string exvoid(<static-cast>(const
ASKER
thanks both evilrix and efn
>> std::string exvoid(<static-cast>(const char *) lpVoid);
std::string exvoid(static_cast<const char *>(lpVoid));
std::string exvoid(static_cast<const char *>(lpVoid));
Right, thanks.
Open in new window