can we do "string to LPCVOID" ??
can we do "string to LPCVOID" ??
Assuming std::string, then it's just "str.c_str()".
Some information on the context in which this is being done would be helpful - including the actual type of "string".
gg
thanks for reply but I tried this I get error :S
string -> C++ -> no automatic conversion to/from void *, so perhaps all you need is:
If that doesn't work, we need to see the code, and the error message, because we can guess what is wrong for quite a while before getting it right.Code:reinterpret_cast<void *>(str.c_str())
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
this is my code
and this is my errorCode:if(!WriteProcessMemory(hProcess, str, lpszDllPath.c_str(), lpszDllPath.length() + 1, 0))
and "lpszDllPath" is string.. thanks for reply and sory my english..Code:error C2664: 'WriteProcessMemory' : cannot convert parameter 3 from 'const char *' to 'void *'
In this case, it is safe to convert to void*.
It doesn't work because c_str() returns const char*, and the function takes void* (thus you disregard the const specifier).
Try:
Code:if(!WriteProcessMemory(hProcess, str, const_cast<char*>( lpszDllPath.c_str() ), lpszDllPath.length() + 1, 0))
I tried it but I got another error.. It is
Code:error C2440: 'reinterpret_cast' : cannot convert from 'const char *' to 'void *'
Irrelevant. Char* can be implicitly converted to void*.
However, const char* cannot be implicitly converted to void* because it's const. Const void* works.
Therefore, we must cast away the const, so const char* -> char* -> void*.
It works. I tried it.
But if you want to do it the C-way, be my guest.
Originally Posted by koyboyYou should update your Platform SDK. See this thread for links: http://cboard.cprogramming.com/showthread.php?t=79619Originally Posted by MSDN
In the meantime, open up your <winbase.h> and change the 3rd parameter type to LPCVOID.
gg