diff --git a/src/constants.h b/src/constants.h index b71abee..3b3a336 100644 --- a/src/constants.h +++ b/src/constants.h @@ -30,4 +30,8 @@ static const IID licenseAgentIID2 = {0x6A07C5A3, 0x9C67, 0x4BB6, {0xB0, 0x20, 0x 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?)"; +__inline static constexpr float XP_NTVER = 5.1f; + +__inline static constexpr float XP64_NTVER = 5.2f; + #endif // XP_ACTIVATE32_CONSTANTS_H_ diff --git a/src/strings.cc b/src/strings.cc index 0f7413d..b1598e7 100644 --- a/src/strings.cc +++ b/src/strings.cc @@ -4,8 +4,7 @@ std::wstring stringToWstring(const std::string& str) { if (str.empty()) { return std::wstring(); } -// Windows: convert UTF-8 → UTF-16 -#ifdef _WIN32 +#ifdef _WIN32 // Windows: convert 1252/UTF-8 → UTF-16 // Get length of string int wide_len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0); if (wide_len == 0) { @@ -20,15 +19,14 @@ std::wstring stringToWstring(const std::string& str) { if (!result.empty() && result.back() == L'\0') { result.pop_back(); } -// POSIX systems: convert UTF-8 → UTF-32 wchar_t -#else +#else // POSIX systems: convert UTF-8 → UTF-16/32 wchar_t // Set locale for multibyte conversion (thread-local) std::mbstate_t state{}; const char* src = str.c_str(); // find required size size_t len = std::mbsrtowcs(nullptr, &src, 0, &state); if (len == static_cast(-1)) { - throw std::runtime_error("mbsrtowcs failed"); + throw std::runtime_error("mbsrtowcs failed!"); } std::wstring result(len, L'\0'); @@ -43,4 +41,46 @@ std::string WstringToString(const std::wstring& wstr) { if (wstr.empty()) { return std::string(); } +#ifdef _WIN32 // Windows: UTF-16 → UTF-8/1252 + int utf8_len = WideCharToMultiByte( + CP_UTF8, 0, + wstr.c_str(), -1, + nullptr, 0, + nullptr, nullptr + ); + + if (utf8_len == 0) { + throw std::runtime_error("WideCharToMultiByte failed!"); + } + + // Convert + std::string result(utf8_len, '\0'); + WideCharToMultiByte( + CP_UTF8, 0, + wstr.c_str(), -1, + &result[0], utf8_len, + nullptr, nullptr + ); + + // Remove trailing null terminator + if (!result.empty() && result.back() == '\0') { + result.pop_back(); + } +#else // POSIX: UTF-16/32 → UTF-8 + std::mbstate_t state{}; + const wchar_t* src = wstr.c_str(); + + // Determine required buffer size + size_t len = std::wcsrtombs(nullptr, &src, 0, &state); + if (len == static_cast(-1)) { + throw std::runtime_error("wcsrtombs failed!"); + } + + std::string result(len, '\0'); + + state = std::mbstate_t{}; + src = wstr.c_str(); + std::wcsrtombs(result.data(), &src, len, &state); +#endif + return result; } diff --git a/src/version.h b/src/version.h index 40ab092..9f13024 100644 --- a/src/version.h +++ b/src/version.h @@ -20,8 +20,8 @@ // These next few lines are where we control version number and copyright year // Adhere to semver > semver.org #define MAJOR_VERSION 1 -#define MINOR_VERSION 0 -#define BUILD_VERSION 3 +#define MINOR_VERSION 1 +#define BUILD_VERSION 4 #define MAIN_TITLE L"XP_Activate32" diff --git a/src/xp_activate32.cc b/src/xp_activate32.cc index 9286f2f..891d1b6 100644 --- a/src/xp_activate32.cc +++ b/src/xp_activate32.cc @@ -1081,9 +1081,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine std::wcout << L"Windows Version: " << GetOSNameW() << std::endl; std::wcout << L"NT Version = " << GetWinVersionW() << std::endl; - constexpr float xp_ntver = 5.1f; - constexpr float xp64_ntver = 5.2f; - if (WinVer != xp_ntver && WinVer != xp64_ntver) { + if (WinVer != XP_NTVER && WinVer != XP64_NTVER) { int user_response_code; user_response_code = MessageBoxW(nullptr, XP_MISMATCH, L"Windows Version Mismatch!", @@ -1108,14 +1106,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine // 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; } + for (i = 0; i < 2; i++) { + DestroyIcon(hIcon[i]); + } + if (LicenseAgent) { LicenseAgent->Release(); }