fix CreateProcessW use
This commit is contained in:
+17
-8
@@ -214,6 +214,7 @@ void platform::new_engine_instance(const std::vector<std::string>& args) {
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
ss << util::quote(executable.u8string());
|
||||||
for (int i = 0; i < args.size(); i++) {
|
for (int i = 0; i < args.size(); i++) {
|
||||||
ss << " " << util::quote(args[i]);
|
ss << " " << util::quote(args[i]);
|
||||||
}
|
}
|
||||||
@@ -230,30 +231,38 @@ void platform::new_engine_instance(const std::vector<std::string>& args) {
|
|||||||
}
|
}
|
||||||
std::vector<wchar_t> buffer(size + 1);
|
std::vector<wchar_t> buffer(size + 1);
|
||||||
buffer[size] = 0;
|
buffer[size] = 0;
|
||||||
MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, buffer.data(), size);
|
size = MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, buffer.data(), size);
|
||||||
return std::wstring(buffer.data(), size);
|
if (size == 0) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"MultiByteToWideChar failed with code: " +
|
||||||
|
std::to_string(GetLastError())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return std::wstring(buffer.data(), size + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto executableString = toWString(executable.u8string());
|
auto commandString = toWString(ss.str());
|
||||||
auto argsString = toWString(ss.str());
|
|
||||||
|
|
||||||
STARTUPINFOW si = { sizeof(si) };
|
STARTUPINFOW si = { sizeof(si) };
|
||||||
PROCESS_INFORMATION pi = { 0 };
|
PROCESS_INFORMATION pi = { 0 };
|
||||||
DWORD flags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS;
|
DWORD flags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS;
|
||||||
// | CREATE_NO_WINDOW;
|
// | CREATE_NO_WINDOW;
|
||||||
BOOL success = CreateProcessW(
|
BOOL success = CreateProcessW(
|
||||||
executableString.c_str(),
|
nullptr,
|
||||||
argsString.data(),
|
commandString.data(),
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
FALSE,
|
FALSE,
|
||||||
flags,
|
flags,
|
||||||
nullptr,
|
nullptr,
|
||||||
L"",
|
nullptr,
|
||||||
&si,
|
&si,
|
||||||
&pi
|
&pi
|
||||||
);
|
);
|
||||||
if (!success) {
|
if (success) {
|
||||||
|
CloseHandle(pi.hProcess);
|
||||||
|
CloseHandle(pi.hThread);
|
||||||
|
} else {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"starting an engine instance failed with code: " +
|
"starting an engine instance failed with code: " +
|
||||||
std::to_string(GetLastError())
|
std::to_string(GetLastError())
|
||||||
|
|||||||
Reference in New Issue
Block a user