diff --git a/src/constants.h b/src/constants.h index ab3bdd3..cf4749c 100644 --- a/src/constants.h +++ b/src/constants.h @@ -1,9 +1,13 @@ #ifndef XP_ACTIVATE32_CONSTANTS_H_ #define XP_ACTIVATE32_CONSTANTS_H_ +#include "framework.h" + #include #include +#include "resource.h" + #define assert(x) /*nothing*/ typedef int64_t i64; diff --git a/src/framework.h b/src/framework.h new file mode 100644 index 0000000..39fc11a --- /dev/null +++ b/src/framework.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#define WINVER _WIN32_WINNT_WINXP +#define _WIN32_WINNT _WIN32_WINNT_WINXP +#define _WIN64_WINNT _WIN32_WINNT_WS03s // Minimum version for 64 bit +#define _WIN32_IE 0x0600 // Minimum Internet Explorer version + +// See https://tedwvc.wordpress.com/2014/01/01/how-to-target-xp-with-vc2012-or-vc2013-and-continue-to-use-the-windows-8-x-sdk/ +//#define _USING_V110_SDK71_ +#define _ATL_XP_TARGETING + +#include + +#include +#include +#include +#include + +#include +#include +#include diff --git a/src/keygen.cc b/src/keygen.cc new file mode 100644 index 0000000..dffa924 --- /dev/null +++ b/src/keygen.cc @@ -0,0 +1,4 @@ +#include "keygen.h" + +#include "utils.h" + diff --git a/src/keygen.h b/src/keygen.h new file mode 100644 index 0000000..231800d --- /dev/null +++ b/src/keygen.h @@ -0,0 +1,7 @@ +#ifndef XP_ACTIVATE32_KEYGEN_H_ +#define XP_ACTIVATE32_KEYGEN_H_ + +#include "constants.h" +#include "framework.h" + +#endif // XP_ACTIVATE32_KEYGEN_H_ diff --git a/src/utils.cc b/src/utils.cc new file mode 100644 index 0000000..5c63f62 --- /dev/null +++ b/src/utils.cc @@ -0,0 +1,67 @@ +#include "utils.h" + +HANDLE LoadImageFromDLL(LPCWSTR dllName, + UINT resourceId, + UINT imgType, + int width, + int height, + UINT flags) { + // Load the .dll module from supplied name + HMODULE hModule = LoadLibraryW(dllName); + if (!hModule) { + return nullptr; + } + + // Load the image using LoadImageW + HANDLE hImage; + hImage = LoadImageW( + hModule, // hinst + MAKEINTRESOURCEW(resourceId), // resource name/id + imgType, + width, + height, + flags); + + // We can free the module after loading unless caller wants otherwise + if (hImage) { + FreeLibrary(hModule); + } + + return hImage; +} + +HICON getDialogIcon(bool use_custom_icon, int resource, int x, int y) { + HICON icon; + // Get key icon + static const LPCWSTR dll_name = L"shell32.dll"; + if (use_custom_icon) { + icon = (HICON)LoadImageFromDLL( + dll_name, + resource, + IMAGE_ICON, + x, + y, + LR_DEFAULTCOLOR); + } else { + icon = (HICON)LoadImage( + GetModuleHandle(NULL), + MAKEINTRESOURCE(IDI_SMALL), // Our normal telephone icon + IMAGE_ICON, + x, + y, + LR_DEFAULTCOLOR); + } + return icon; +} + +std::string getVersionA() { + std::ostringstream ostr; + ostr << MAJOR_VERSION << "." << MINOR_VERSION << L"." << BUILD_VERSION; + return ostr.str(); +} + +std::wstring getVersionW() { + std::wostringstream wostr; + wostr << MAJOR_VERSION << L"." << MINOR_VERSION << L"." << BUILD_VERSION; + return wostr.str(); +} diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..75fe794 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,23 @@ +#ifndef XP_ACTIVATE32_UTILS_H_ +#define XP_ACTIVATE32_UTILS_H_ + +#include "constants.h" +#include "framework.h" + +// Function to load arbitrary .ico from arbitrary .dll +HANDLE LoadImageFromDLL(LPCWSTR dllName, + UINT resourceId, + UINT imgType, + int width, + int height, + UINT flags); + +// Decide what icon to use for main dialog +HICON getDialogIcon(bool use_custom_icon, int resource, int x, int y); + +// Version getter functions +std::string getVersionA(); + +std::wstring getVersionW(); + +#endif // XP_ACTIVATE32_UTILS_H_ diff --git a/src/version.h b/src/version.h index 5b733ad..d6ac6b5 100644 --- a/src/version.h +++ b/src/version.h @@ -3,19 +3,6 @@ #pragma code_page(65001) // UTF-8 -#include - -#define WINVER _WIN32_WINNT_WINXP -#define _WIN32_WINNT _WIN32_WINNT_WINXP -#define _WIN64_WINNT _WIN32_WINNT_WS03s // Minimum version for 64 bit -#define _WIN32_IE 0x0600 // Minimum Internet Explorer version - -// See https://tedwvc.wordpress.com/2014/01/01/how-to-target-xp-with-vc2012-or-vc2013-and-continue-to-use-the-windows-8-x-sdk/ -//#define _USING_V110_SDK71_ -#define _ATL_XP_TARGETING - -#include - // Macro to convert to string #if !defined(_STRINGIZER) && !defined(STRINGIZE) #define _STRINGIZER(in) #in diff --git a/src/xp_activate32.cc b/src/xp_activate32.cc index 5f64229..6285416 100644 --- a/src/xp_activate32.cc +++ b/src/xp_activate32.cc @@ -1,7 +1,7 @@ #include "xp_activate32.h" -#include -#include +#include "keygen.h" +#include "utils.h" static HICON hIcon[2]; @@ -972,66 +972,6 @@ INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) return FALSE; } -HANDLE LoadImageFromDLL(LPCWSTR dllName, - UINT resourceId, - UINT imgType, - int width, - int height, - UINT flags) { - // Load the .dll module from supplied name - HMODULE hModule = LoadLibraryW(dllName); - if (!hModule) { - return nullptr; - } - - // Load the image using LoadImageW - HANDLE hImage; - hImage = LoadImageW( - hModule, // hinst - MAKEINTRESOURCEW(resourceId), // resource name/id - imgType, - width, - height, - flags); - - // We can free the module after loading unless caller wants otherwise - if (hImage) { - FreeLibrary(hModule); - } - - return hImage; -} - -HICON getDialogIcon(bool use_custom_icon, int resource, int x, int y) { - HICON icon; - // Get key icon - static const LPCWSTR dll_name = L"shell32.dll"; - if (use_custom_icon) { - icon = (HICON)LoadImageFromDLL( - dll_name, - resource, - IMAGE_ICON, - x, - y, - LR_DEFAULTCOLOR); - } else { - icon = (HICON)LoadImage( - GetModuleHandle(NULL), - MAKEINTRESOURCE(IDI_SMALL), // Our normal telephone icon - IMAGE_ICON, - x, - y, - LR_DEFAULTCOLOR); - } - return icon; -} - -std::wstring getVersionW() { - std::wostringstream ostr; - ostr << MAJOR_VERSION << L"." << MINOR_VERSION << L"." << BUILD_VERSION; - return ostr.str(); -} - int main() { std::wstring welcome_str = L"Welcome to XP_Activate32 ver. " + getVersionW(); std::wcout << welcome_str << std::endl; @@ -1043,10 +983,9 @@ int main() { LoadString(NULL, i, strings[i], sizeof(strings[i]) / sizeof(strings[i][0])); } - int x, y; for (i = 0; i < 2; i++) { - x = GetSystemMetrics(i ? SM_CXICON : SM_CXSMICON); - y = GetSystemMetrics(i ? SM_CYICON : SM_CYSMICON); + int x = GetSystemMetrics(i ? SM_CXICON : SM_CXSMICON); + int y = GetSystemMetrics(i ? SM_CYICON : SM_CYSMICON); hIcon[i] = getDialogIcon(false, 194, x, y); } diff --git a/src/xp_activate32.h b/src/xp_activate32.h index 4097f16..4d38f15 100644 --- a/src/xp_activate32.h +++ b/src/xp_activate32.h @@ -1,13 +1,11 @@ #ifndef XP_ACTIVATE32_H_ #define XP_ACTIVATE32_H_ -#include "resource.h" - #include -#include -#include #include "constants.h" +#include "framework.h" +#include "resource.h" #ifndef STRICT #define STRICT diff --git a/xp_activate32.vcxproj b/xp_activate32.vcxproj index b84f59e..f9e9288 100644 --- a/xp_activate32.vcxproj +++ b/xp_activate32.vcxproj @@ -151,12 +151,17 @@ + + + + + diff --git a/xp_activate32.vcxproj.filters b/xp_activate32.vcxproj.filters index e9033a0..0b4f98e 100644 --- a/xp_activate32.vcxproj.filters +++ b/xp_activate32.vcxproj.filters @@ -23,6 +23,12 @@ + + Source Files + + + Source Files + Source Files @@ -31,12 +37,21 @@ Header Files + + Header Files + + + Header Files + Header Files Header Files + + Header Files + Header Files