Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert LPWSTR to string

Tags:

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.

like image 799
leggo Avatar asked Sep 17 '12 13:09

leggo


People also ask

How do you convert Lpwstr to string?

string MyString = CW2A (L"sometext"); Also, consider using wstring instead of string.

How do you convert Lpcwstr to Lpwstr?

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.

What is Lpwstr C++?

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").

What is a Wstring?

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.


2 Answers

std::string MyString = CW2A (L"LPWSTR STRING"); 

You need to include atlstr.h for CW2A

like image 113
Chris Dargis Avatar answered Oct 03 '22 23:10

Chris Dargis


Try to use following API functions :

  1. WideCharToMultiByte

  2. wcstombs

And comparision of both methods WideCharToMultiByte() vs. wcstombs()

like image 26
rkosegi Avatar answered Oct 03 '22 23:10

rkosegi