Created
March 10, 2020 05:53
-
-
Save derekgates/633264e1d788be24a01adc109fea9e2f to your computer and use it in GitHub Desktop.
C++: convert strings to a usable string in MessageBox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//used to convert strings to a usable string in MessageBox, example: | |
//std::wstring stemp = s2ws(executablePath); | |
//MessageBox(0, stemp.c_str(), L"", MB_OK); | |
//https://stackoverflow.com/a/27296 | |
std::wstring s2ws(const std::string& s) | |
{ | |
int len; | |
int slength = (int)s.length() + 1; | |
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); | |
wchar_t* buf = new wchar_t[len]; | |
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); | |
std::wstring r(buf); | |
delete[] buf; | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment