【发布时间】:2019-04-05 19:19:27
【问题描述】:
char*与LPWSTR参数不兼容
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);
}
还有其他方法可以解决这个问题吗?
【问题讨论】:
-
然后呢?是的,它们不兼容:msdn.microsoft.com/en-us/library/cc230355.aspx
-
您使用 char 字符串而不是标准字符串的任何原因?
-
@JakeFreeman 请定义“标准字符串”
-
@jak:所以
std::wstring不是“标准字符串” 类型?是的,有 are 理由不使用 C++ 字符串类型。将事物 C 保持在接口边界上要容易得多。 -
@bar:这不正确。 CreateProcessW 需要一个 mutable 字符串作为其第二个参数。字符串文字不行。