简体   繁体   中英

cannot convert parameter 1 from 'CHAR [260]' to 'const std::basic_string<_Elem,_Traits,_Ax>

Hi when i compile my code i have that error my problem on 2 lines that included : if ( !processName.compare(processInfo.szExeFile) ) also i use multiply-byte character but i don't know why have same problem?

my error is:

int std::basic_string<_Elem,_Traits,_Ax>::compare(const std::basic_string<_Elem,_Traits,_Ax> &) const' : 
cannot convert parameter 1 from 'CHAR [260]' to 'const std::basic_string<_Elem,_Traits,_Ax> &'

and my code:

 #include<fstream>
 #include<sstream>
 #include<string>
 #include<iostream>
 #include<iomanip>
 #include<cstdlib>
 #include<Windows.h>
 #include<TlHelp32.h>

using std::ifstream;
using std::string;
using std::getline;
using std::ios;
using std::cerr;
using std::cout;
using std::endl;
using std::fixed;
using std::left;
using std::right;
using std::showpoint;
using std::cin;

class check {

public :


void check_seta () {

    ifstream cfgm2("fix.cfg",ios::in);

    string cfgLine;

    while (getline(cfgm2,cfgLine)) {

        if (string::npos != cfgLine.find("pn ff")){

             if (cfgLine.at(19) == '0'){

                 MessageBoxW(NULL , L"naananaana",NULL,MB_ICONERROR); 

                 std::wstring Processname(L"lol.exe");

                 DWORD ProcessId = FindProcessId(Processname);

                 HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, TRUE ,ProcessId);

                 TerminateProcess(pHandle,0);

                 CloseHandle(pHandle);
             }
             break;
        }

    }
  }

 DWORD FindProcessId(const std::wstring& processName)
    {
    PROCESSENTRY32 processInfo;
    processInfo.dwSize = sizeof(processInfo);

    HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
    if ( processesSnapshot == INVALID_HANDLE_VALUE )
    return 0;

    Process32First(processesSnapshot, &processInfo);

    // I have problem in this line

    if ( !processName.compare(processInfo.szExeFile) )
    {
        CloseHandle(processesSnapshot);
        return processInfo.th32ProcessID;
    }

    while ( Process32Next(processesSnapshot, &processInfo) )
    {

    // and I have problem with this line

        if ( !processName.compare(processInfo.szExeFile) )
        {
            CloseHandle(processesSnapshot);
            return processInfo.th32ProcessID;
        }
    }

    CloseHandle(processesSnapshot);
    return 0;
  }
 };

processName is a wstring. wstring and string are not compatible, nor can wstring be initialized by char *.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM