CreateProcess使用路径时的错误事件:类型为“char *”的E0167参数与“LPWSTR”类型的参数不兼容

问题描述 投票:-4回答:1

当我在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);
}
c++ winapi createprocess
1个回答
0
投票

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

    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);
}

© www.soinside.com 2019 - 2024. All rights reserved.