创建进程使用路径时出现错误事件:类型 "char *" 的 E0167 参数与类型 "LPWSTR" 的参数不兼容

Error events when CreateProcess uses a path: E0167 argument of type "char *" is incompatible with parameter of type "LPWSTR"

本文关键字:类型 参数 char 不兼容 LPWSTR E0167 路径 进程 事件 错误 创建      更新时间:2023-10-16

当我在C++ VisualStudio 2017中使用CreateProcess命令时,我给出了一个关于LPWSTR的错误:类型为"char *"的 E0167 参数与类型为"LPWSTR"的参数不兼容。

我该如何解决它?波纹管代码是我关于该问题的代码的一部分。感谢您的任何建议。

int main()
{
...
    ConnectToEngine("stockfish.exe");
...
}

void ConnectToEngine(char* path)
{
    pipin_w = pipin_r = pipout_w = pipout_r = NULL;
    sats.nLength = sizeof(sats);
    sats.bInheritHandle = TRUE;
    sats.lpSecurityDescriptor = NULL;
    CreatePipe(&pipout_r, &pipout_w, &sats, 0);
    CreatePipe(&pipin_r, &pipin_w, &sats, 0);
    sti.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    sti.wShowWindow = SW_HIDE;
    sti.hStdInput = pipin_r;
    sti.hStdOutput = pipout_w;
    sti.hStdError = pipout_w;
    CreateProcess(NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &sti, &pi);
}

问题通过上面朋友的一些笔记修复。工作代码如下:

    int main()
   {
    ...
    wchar_t a[] = L"stockfish.exe";
    ConnectToEngine(a);
    ...
   }

void ConnectToEngine(WCHAR* path)
{
    pipin_w = pipin_r = pipout_w = pipout_r = NULL;
    sats.nLength = sizeof(sats);
    sats.bInheritHandle = TRUE;
    sats.lpSecurityDescriptor = NULL;
    CreatePipe(&pipout_r, &pipout_w, &sats, 0);
    CreatePipe(&pipin_r, &pipin_w, &sats, 0);
    sti.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    sti.wShowWindow = SW_HIDE;
    sti.hStdInput = pipin_r;
    sti.hStdOutput = pipout_w;
    sti.hStdError = pipout_w;
    CreateProcess(NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &sti, &pi);
}