Print the windows error string when CreateProcess fails to create the emulation process
This commit is contained in:
parent
a6e17bc4de
commit
5e7c6a082f
|
@ -83,6 +83,7 @@ file (GLOB CXBXR_HEADER_COMMON
|
|||
"${CXBXR_ROOT_DIR}/src/common/win32/EmuShared.h"
|
||||
"${CXBXR_ROOT_DIR}/src/common/win32/Mutex.h"
|
||||
"${CXBXR_ROOT_DIR}/src/common/win32/Threads.h"
|
||||
"${CXBXR_ROOT_DIR}/src/common/win32/Util.h"
|
||||
"${CXBXR_ROOT_DIR}/src/common/win32/WineEnv.h"
|
||||
"${CXBXR_ROOT_DIR}/src/common/xbdm/CxbxXbdm.h"
|
||||
"${CXBXR_ROOT_DIR}/src/common/xbe/Xbe.h"
|
||||
|
@ -246,6 +247,7 @@ file (GLOB CXBXR_SOURCE_COMMON
|
|||
"${CXBXR_ROOT_DIR}/src/common/win32/IPCWindows.cpp"
|
||||
"${CXBXR_ROOT_DIR}/src/common/win32/Mutex.cpp"
|
||||
"${CXBXR_ROOT_DIR}/src/common/win32/Threads.cpp"
|
||||
"${CXBXR_ROOT_DIR}/src/common/win32/Util.cpp"
|
||||
"${CXBXR_ROOT_DIR}/src/common/win32/WineEnv.cpp"
|
||||
"${CXBXR_ROOT_DIR}/src/common/xbdm/CxbxXbdm.cpp"
|
||||
"${CXBXR_ROOT_DIR}/src/common/xbe/Xbe.cpp"
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "core\kernel\init\CxbxKrnl.h"
|
||||
#include "common/util/cliConfig.hpp"
|
||||
#include "Util.h"
|
||||
|
||||
// Source: https://stackoverflow.com/questions/8046097/how-to-check-if-a-process-has-the-administrative-rights
|
||||
bool CxbxIsElevated() {
|
||||
|
@ -69,7 +70,7 @@ std::optional<std::string> CxbxExec(bool useDebugger, HANDLE* hProcess, bool req
|
|||
cpu load cycles to get the task done.
|
||||
*/
|
||||
if (CreateProcess(nullptr, const_cast<LPSTR>(szProcArgsBuffer.c_str()), nullptr, nullptr, false, 0, nullptr, nullptr, &startupInfo, &processInfo) == 0) {
|
||||
return std::make_optional<std::string>("Failed to create the new emulation process (another instance of cxbxr is already running?)");
|
||||
return std::make_optional<std::string>("Failed to create the new emulation process. CreateProcess failed because: " + WinError2Str());
|
||||
}
|
||||
CloseHandle(processInfo.hThread);
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// ******************************************************************
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2021 ergo720
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
|
||||
#include "Util.h"
|
||||
#include "Windows.h"
|
||||
|
||||
|
||||
std::string WinError2Str()
|
||||
{
|
||||
DWORD error_id = GetLastError();
|
||||
if (error_id == ERROR_SUCCESS) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
LPSTR msg_buff = nullptr;
|
||||
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, error_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPSTR>(&msg_buff), 0, nullptr);
|
||||
|
||||
std::string msg(msg_buff, size);
|
||||
LocalFree(msg_buff);
|
||||
|
||||
return msg;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// ******************************************************************
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2021 ergo720
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string WinError2Str();
|
Loading…
Reference in New Issue