【发布时间】:2019-04-23 16:47:45
【问题描述】:
当我在 C++ VisualStudio 2017 中使用 CreateProcess 命令时,我给出了关于 LPWSTR 的错误: E0167 “char *”类型的参数与“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);
}
【问题讨论】:
-
你需要一个
LPWSTR的参数而不是char*,错误信息有什么不清楚的地方? -
如您在此处看到的docs.microsoft.com/en-us/windows/desktop/Intl/…
LPWSTR是typedef的unsigned wchar_t*,而不是char* -
我做到了:char* exename[] = "stockfish.exe"; ConnectToEngine("exename");但它不起作用。错误:E0520 初始化,聚合对象需要“{...}”
-
@nanosi 看看
LPWSTR的定义,不是char*,对应的原始字符串字面量是L前缀。 -
这与您在项目设置中启用
UNICODE有关。话虽如此,您很可能想要进行@πάνταῥεῖ 告诉您的修复。也使用wchar_t*而不是char*。
标签: c++ winapi createprocess