add framework.h as main header, add utils.h/.cc, and keygen.h/.cc to split out more logic
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
#ifndef XP_ACTIVATE32_CONSTANTS_H_
|
||||
#define XP_ACTIVATE32_CONSTANTS_H_
|
||||
|
||||
#include "framework.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#define assert(x) /*nothing*/
|
||||
|
||||
typedef int64_t i64;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <WinSDKVer.h>
|
||||
|
||||
#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 <SDKDDKVer.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
#include <commdlg.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "keygen.h"
|
||||
|
||||
#include "utils.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_
|
||||
@@ -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();
|
||||
}
|
||||
+23
@@ -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_
|
||||
@@ -3,19 +3,6 @@
|
||||
|
||||
#pragma code_page(65001) // UTF-8
|
||||
|
||||
#include <WinSDKVer.h>
|
||||
|
||||
#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 <SDKDDKVer.h>
|
||||
|
||||
// Macro to convert to string
|
||||
#if !defined(_STRINGIZER) && !defined(STRINGIZE)
|
||||
#define _STRINGIZER(in) #in
|
||||
|
||||
+4
-65
@@ -1,7 +1,7 @@
|
||||
#include "xp_activate32.h"
|
||||
|
||||
#include <commctrl.h>
|
||||
#include <sstream>
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -1,13 +1,11 @@
|
||||
#ifndef XP_ACTIVATE32_H_
|
||||
#define XP_ACTIVATE32_H_
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#include <intrin.h>
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "framework.h"
|
||||
#include "resource.h"
|
||||
|
||||
#ifndef STRICT
|
||||
#define STRICT
|
||||
|
||||
@@ -151,12 +151,17 @@
|
||||
<Image Include="src/xp_activate32.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src/keygen.cc" />
|
||||
<ClCompile Include="src/utils.cc" />
|
||||
<ClCompile Include="src/xp_activate32.cc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src/constants.h" />
|
||||
<ClInclude Include="src/framework.h" />
|
||||
<ClInclude Include="src/keygen.h" />
|
||||
<ClInclude Include="src/resource.h" />
|
||||
<ClInclude Include="src/xp_activate32.h" />
|
||||
<ClInclude Include="src/utils.h" />
|
||||
<ClInclude Include="src/version.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src/keygen.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src/utils.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src/xp_activate32.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -31,12 +37,21 @@
|
||||
<ClInclude Include="src/constants.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/framework.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/keygen.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/xp_activate32.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/version.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
||||
Reference in New Issue
Block a user