c++ - CreateProcess 使用路径时的错误事件:“char *”类型的 E0167 参数与“LPWSTR”类型的参数不兼容
问题描述
当我在 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);
}
推荐阅读
- metrics - Google Cloud Monitoring Ruby 客户端权限问题
- c# - c#中的字典对象
- python - 通过 API Gateway Lambda AWS- Python 上传多个 pdf 文件
- wordpress - 将 Woocommerce Zoom 添加到自定义库
- sublimetext3 - 如何在 Sublime 中为字符串添加引号?
- kotlin - 如何初始化lateinit变量?
- javascript - VueJs 成功后清除表单
- android - 左右动画回收器视图项目以告诉用户滑动选项
- java - 通过不使用 SharedPreferences 的 Google 登录自动登录
- flutter - 在 GrapghQl Flutter 包设置中缓存以及如何检查它是否有效