Loader : Shared implementation for termining guiProcessID (and "2nd GUI" mode?!)

This commit is contained in:
PatrickvL 2019-02-11 16:14:02 +01:00 committed by RadWolfie
parent 170b971a8e
commit 254e666bfe
4 changed files with 52 additions and 32 deletions

View File

@ -872,11 +872,38 @@ void ImportLibraries(XbeImportEntry *pImportDirectory)
}
}
bool CheckLoadArgument(int argc, char* argv[], DWORD *pguiProcessID)
{
bool bHasLoadArgument;
if (argc >= 2 && std::strcmp(argv[1], "/load") == 0 && std::strlen(argv[2]) > 0) {
HWND hWnd = nullptr;
bHasLoadArgument = true;
// Perform check if command line contain gui's hWnd value.
if (argc > 3) {
hWnd = (HWND)std::stoi(argv[3], nullptr, 10);
hWnd = IsWindow(hWnd) ? hWnd : nullptr;
if (hWnd != nullptr) {
// We don't need thread ID from window handle.
GetWindowThreadProcessId(hWnd, pguiProcessID);
}
}
}
else {
bHasLoadArgument = false;
*pguiProcessID = GetCurrentProcessId();
}
g_exec_filepath = argv[0]; // NOTE: Workaround solution until simulated "main" function is made.
return bHasLoadArgument;
}
bool CreateSettings()
{
g_Settings = new Settings();
if (g_Settings == nullptr) {
MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK);
MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK | MB_ICONERROR);
return false;
}

View File

@ -224,6 +224,8 @@ bool CxbxKrnlVerifyVersion(const char *szVersion);
extern bool g_bIsDebugKernel;
bool CheckLoadArgument(int argc, char* argv[], DWORD *pguiProcessID);
bool CreateSettings();
bool HandleFirstLaunch();

View File

@ -133,30 +133,40 @@ DWORD WINAPI Emulate(int system)
/*! Verify our host executable, CxbxLoader.exe, is loaded to base address 0x00010000 */
if (!VerifyBaseAddr()) {
MessageBox(NULL, "CxbxLoader.exe was not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)", "Cxbx-Reloaded", MB_OK);
MessageBox(NULL, "CxbxLoader.exe was not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)", "Cxbx-Reloaded",
MB_OK | MB_ICONERROR);
return EXIT_FAILURE;
}
// Before doing anything else that might cause memory fragmentation,
// verify that we still got control over all ranges the loader reserved
if (!VerifyAddressRanges(system)) {
MessageBox(NULL, "Failed to claim required address ranges (which is a requirement for Xbox emulation)", "Cxbx-Reloaded", MB_OK);
MessageBox(NULL, "Failed to claim required address ranges (which is a requirement for Xbox emulation)", "Cxbx-Reloaded",
MB_OK | MB_ICONERROR);
return EXIT_FAILURE;
}
/*! initialize shared memory */
if (!EmuShared::Init(0)) {
MessageBox(NULL, "Could not map shared memory!", "Cxbx-Reloaded", MB_OK);
return EXIT_FAILURE;
}
HandleFirstLaunch();
LPSTR CommandLine = GetCommandLine();
int argc;
PCHAR *argv = CommandLineToArgvA(CommandLine, &argc);
CxbxKrnlMain(argc, argv);
DWORD guiProcessID = 0;
bool bHasLoadArgument = CheckLoadArgument(argc, argv, &guiProcessID);
/*! initialize shared memory */
if (!EmuShared::Init(guiProcessID)) {
MessageBox(NULL, "Could not map shared memory!", "Cxbx-Reloaded", MB_OK | MB_ICONERROR);
LocalFree(argv);
return EXIT_FAILURE;
}
HandleFirstLaunch();
if (bHasLoadArgument) {
CxbxKrnlMain(argc, argv);
} else {
// TODO : Enter "2nd GUI" mode here, as done in Cxbx's WinMain() - but how?
}
LocalFree(argv);

View File

@ -60,28 +60,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return EXIT_FAILURE;
}
bool bHasLoadArgument;
HWND hWnd = nullptr;
DWORD guiProcessID = 0;
// TODO: Convert ALL __argc & __argv to use main(int argc, char** argv) method.
if (__argc >= 2 && std::strcmp(__argv[1], "/load") == 0 && std::strlen(__argv[2]) > 0) {
bHasLoadArgument = true;
// Perform check if command line contain gui's hWnd value.
if (__argc > 3) {
hWnd = (HWND)std::stoi(__argv[3], nullptr, 10);
hWnd = IsWindow(hWnd) ? hWnd : nullptr;
if (hWnd != nullptr) {
// We don't need thread ID from window handle.
GetWindowThreadProcessId(hWnd, &guiProcessID);
}
}
} else {
bHasLoadArgument = false;
guiProcessID = GetCurrentProcessId();
}
g_exec_filepath = __argv[0]; // NOTE: Workaround solution until simulated "main" function is made.
bool bHasLoadArgument = CheckLoadArgument(__argc, __argv, &guiProcessID);
/*! initialize shared memory */
EmuShared::Init(guiProcessID);