当我在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);
}