0

I encountered this error:

std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const _Alloc &)': cannot convert argument 1 from 'TCHAR *' to 'std::initializer_list<_Elem>'

Below I have added the code:

        DWORD pid;
        GetWindowThreadProcessId(hwnd, &pid);
        if (pid == param) {
            TCHAR classNameBuf[MAX_PATH];
            GetClassName(hwnd, classNameBuf, MAX_PATH);
            std::string className(&classNameBuf[0]);
            if (className != ("MSCTFIME UI") && className != ("IME") && className != ("ConsoleWindowClass")) {
                window_handle = hwnd;
                return false;
            }
        }
        return true;
    }
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
StackBot
  • 1
  • 2
  • 2
    `("MSCTFIME UI")` -> `_T("MSCTFIME UI")` etc. and `std::string` -> `std::wstring`. – Jabberwocky Apr 21 '22 at 09:58
  • 1
    `TCHAR` is obsolete; use `wchar_t`, see [here](https://stackoverflow.com/q/234365), [here](https://stackoverflow.com/a/33962409) and [here](https://blogs.msmvps.com/gdicanio/2016/10/10/a-friendly-piece-of-advice-the-tchar-model-forget-about-it/). `GetClassName` -> `GetClassNameW`, `_T("MSCTFIME UI")` -> `L"MSCTFIME UI"`, etc. – Axalo Apr 21 '22 at 10:31
  • Your question is implied by your title, you should state clearly in the body what your question is to clarify what you are asking of the community. – mazecreator Apr 21 '22 at 19:10
  • What character set are you using? – Minxin Yu - MSFT Apr 22 '22 at 02:42
  • See [C2664](https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2664?view=msvc-170) – Minxin Yu - MSFT Apr 22 '22 at 05:57

0 Answers0