Function CommandLineToArgvW
is giving me commandline arguments in LPWSTR
type. I need these arguments in string
. Would someone please tell me how to convert LPWSTR
to string
?
I'm using mingw.
string MyString = CW2A (L"sometext"); Also, consider using wstring instead of string.
LPCWSTR is a pointer to a const string buffer. LPWSTR is a pointer to a non-const string buffer. Just create a new array of wchar_t and copy the contents of the LPCWSTR to it and use it in the function taking a LPWSTR.
The LPWSTR type is a 32-bit pointer to a string of 16-bit Unicode characters, which MAY be null-terminated. The LPWSTR type specifies a pointer to a sequence of Unicode characters, which MAY be terminated by a null character (usually referred to as "null-terminated Unicode").
Description. An operand of data type WSTRING (Wide String) stores several Unicode characters of data type WCHAR in one character string. If you do not specify a length, the character string has a preset length of 254 characters. In a character string, all characters of the Unicode format are permitted.
std::string MyString = CW2A (L"LPWSTR STRING");
You need to include atlstr.h
for CW2A
Try to use following API functions :
WideCharToMultiByte
wcstombs
And comparision of both methods WideCharToMultiByte() vs. wcstombs()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With