将TCHAR转换为char*以用于strstr函数

use*_*258 0 c c++ qt

    char skype[6] = "Skype";
    HWND firstwindow = FindWindowEx(NULL, NULL, NULL, NULL);
    HWND window = firstwindow;
    TCHAR windowtext[MAX_PATH]; //search term

    //We need to get the console title in case we
    //accidentally match the search word with it
    //instead of the intended target window.
    TCHAR consoletitle[MAX_PATH];
    GetConsoleTitle(consoletitle, MAX_PATH);

    while(true){
        //Check window title for a match
        GetWindowText(window, windowtext, MAX_PATH);
        if (strstr(windowtext, skype)!=NULL && strcmp(windowtext, consoletitle)!=0) break; //search for program
            //Get next window
            window = FindWindowEx(NULL, window, NULL, NULL);
        if(window == NULL || window == firstwindow){
            printf("Window not found.\n");
            return 1;
        }
    } //end while
Run Code Online (Sandbox Code Playgroud)
Error: cannot convert 'TCHAR* {aka wchar_t*}' to 'const char*' for argument '1' to 'char* strstr(const char*, const char*)'
Run Code Online (Sandbox Code Playgroud)

此行出现问题:

if (strstr(windowtext, skype)!=NULL && strcmp(windowtext, consoletitle)!=0) break; //search for program
Run Code Online (Sandbox Code Playgroud)

我在cygwin mingw32gcc编译器中运行相同的程序时没有问题.这是我使用QT mingw32gcc编译器的问题吗?我<windows.h>在一开始就包括在内,所以这不是问题.

编辑:好的所以我添加<tchar.h>并替换if(_tcsstr(windowtext,skype)!= NULL && _tcscmp(windowtext,consoletitle)!= 0)break;

但问题仍然存在:错误:无法将'TCHAR*{aka wchar_t*}'转换为'const char*'以将参数'1'转换为'char*strstr(const char*,const char*)'

Dre*_*wen 6

你应该使用-equivalent,而不是转换为char *使用in ; 它会编译为正确的调用或者.strstrTCHAR_tcsstrstrstrwcsstr