Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast (const) char * to LPCWSTR [duplicate]

I'm trying to use FindWindow() from WinAPI, and I want to ask an input for window's title from the user:

char *input;
cout << "Window title: ";
cin >> input;

Pretty standard. Now then, how do I convert this to LPCWSTR for FindWindow()?

I've already tried the following: _T(input), TEXT(input), (LPCWSTR)input but none of them worked. I also tried using wchar_t instead of char, but I need char everywhere else so then I get dozens of errors for using wchar_t instead of char...

like image 987
Markus Meskanen Avatar asked Dec 15 '22 08:12

Markus Meskanen


1 Answers

You can use the wide variants of cin and cout:

wchar_t input[256];    // don't really use a fixed size buffer!
wcout << L"Window title: ";
wcin >> input;
like image 188
cdmh Avatar answered Dec 28 '22 22:12

cdmh