LPVOID is just void*, so you can convert any pointer to it as any pointer is convertible to void*. However, it does not guarantee that this operation will give valid result in terms of your expectations.
Simply, LPVOID is used in situations according to the following scheme
int i = 10; // some real data
int* pi = &i; // pointer to data
// convert to opaque pointer, not usable (readable), onlly can be passed around
// for instance to thread procedure
void* pv = pi;
pi = reinterpret_cast<int*>(pv); // convert back to pointer to data
int j = *pi; // access real data
The problem is that you have to guarantee that i
will stay alive for at least as long as the data is accessed/used through pv
pointer. You have to consider if your w
So, you can do this:
bool httpWrapper::setPostData(const string &postData){
_postData = reinterpret_cast<LPVOID>(postData.c_str());
return false;
}
but you have to guarantee that the string object you pass by reference as postData
will stay alive for at least as long as _postData
points to it. In fact, _postData
points to internal location of returned by c_str()
Also, it seems you're going to use value returned by c_str()
as LPWSTR
. To use LPWSTR you need to convert from ANSI to wide characters for instance, using MultiByteToWideChar function.
In other words, the conversion from one pointer to another is not a problem itself. The problem is to guarantee proper objects lifetime and usage.