diff --git a/Makefile b/Makefile index 2a07fcf..92711fe 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ $(TARGET): $(OBJ_C) $(OBJ_CPP) $(OBJ_RC) $(CC) $(CFLAGS) -c $< -o $@ # Compile C++ sources -%.o: %.cc +%.o: %.cc $(HEADERS) $(CXX) $(CXXFLAGS) -c $< -o $@ # Compile .rc → .o or .res diff --git a/src/constants.h b/src/constants.h index b7e611c..b71abee 100644 --- a/src/constants.h +++ b/src/constants.h @@ -28,4 +28,6 @@ static const IID licenseAgentIID = {0xB8CBAD79, 0x3F1F, 0x481A, {0xBB, 0x0C, 0xE //IID for ICOMLicenseAgent2, with three extra functions static const IID licenseAgentIID2 = {0x6A07C5A3, 0x9C67, 0x4BB6, {0xB0, 0x20, 0xEC, 0xBE, 0x7F, 0xDF, 0xD3, 0x26}}; +const LPCWSTR XP_MISMATCH = L"It seems you are not running Windows XP, \nwould you like to run the program anyway \nin debug mode for testing?)"; + #endif // XP_ACTIVATE32_CONSTANTS_H_ diff --git a/src/utils.cc b/src/utils.cc index 806f1d1..2cdaa6f 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -444,8 +444,13 @@ std::wstring const GetOSNameW() { return retval; } -std::wstring const GetWinVersion() { - const std::wstring wver = stringToWstring(GetNTString()); +std::string const GetWinVersionA() { + const std::string ver = GetNTString(); + return ver; +} + +std::wstring const GetWinVersionW() { + const std::wstring wver = stringToWstring(GetWinVersionA()); return wver; } diff --git a/src/utils.h b/src/utils.h index 50f371e..a5f4192 100644 --- a/src/utils.h +++ b/src/utils.h @@ -54,8 +54,11 @@ std::string const GetOSNameA(); std::wstring const GetOSNameW(); -std::wstring const GetWinVersion(); +std::string const GetWinVersionA(); +std::wstring const GetWinVersionW(); + +// TODO convert to class and private std::string const GetNTString(); // Debug functions diff --git a/src/xp_activate32.cc b/src/xp_activate32.cc index 8d55283..9286f2f 100644 --- a/src/xp_activate32.cc +++ b/src/xp_activate32.cc @@ -1042,6 +1042,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine UNREFERENCED_PARAMETER(hPrevInstance); /* Assign global HINSTANCE */ g_hInstance = hInstance; + int return_code; + bool open_main_dialog = false; //MSG Msg; long err_status; @@ -1077,15 +1079,41 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine std::wstring welcome_str = L"Welcome to XP_Activate32 ver. " + getVersionW(); std::wcout << welcome_str << std::endl; std::wcout << L"Windows Version: " << GetOSNameW() << std::endl; - std::wcout << L"GetWinVersion() = " << GetWinVersion() << std::endl; - std::cout << "WinVer: " << WinVer << std::endl; + std::wcout << L"NT Version = " << GetWinVersionW() << std::endl; - // Create main window - INT_PTR main_dialog = DialogBoxW(g_hInstance, MAKEINTRESOURCE(100), NULL, &DialogProc); - err_status = static_cast(main_dialog); + constexpr float xp_ntver = 5.1f; + constexpr float xp64_ntver = 5.2f; + if (WinVer != xp_ntver && WinVer != xp64_ntver) { + int user_response_code; + user_response_code = + MessageBoxW(nullptr, XP_MISMATCH, L"Windows Version Mismatch!", + MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1); + if (user_response_code == IDNO) { + std::wcout << L"User declined, exiting..." << std::endl; + return_code = 0; + } else if (user_response_code == IDCANCEL) { + std::wcout << L"User declined, exiting..." << std::endl; + return_code = 0; + } else if (user_response_code == IDYES) { + return_code = 69; + open_main_dialog = true; + } else { + return_code = 2; + } + } else { + open_main_dialog = true; + } - for (i = 0; i < 2; i++) { - DestroyIcon(hIcon[i]); + if (open_main_dialog) { + // Create main window + INT_PTR main_dialog = DialogBoxW(g_hInstance, MAKEINTRESOURCE(100), NULL, &DialogProc); + err_status = static_cast(main_dialog); + + for (i = 0; i < 2; i++) { + DestroyIcon(hIcon[i]); + } + } else { + err_status = 0L; } if (LicenseAgent) { @@ -1097,8 +1125,12 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine } std::wcout << L"err_status = " << err_status << std::endl; - if (err_status != 0L) { + + if (err_status == 0L) { + return_code = 0; + return return_code; + } else { system("pause"); + ExitProcess(err_status); } - ExitProcess(err_status); }