From 9d3d916645e2c2b8392be132dcdcd377ba03ca76 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Fri, 5 Nov 2021 03:59:01 +0200 Subject: [PATCH] Moved QueryVersion API to separate file --- ExplorerPatcher/ExplorerPatcher.vcxproj | 7 +++- .../ExplorerPatcher.vcxproj.filters | 3 ++ ExplorerPatcher/queryversion.h | 35 +++++++++++++++++++ ExplorerPatcher/utility.c | 30 ---------------- ExplorerPatcher/utility.h | 3 +- 5 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 ExplorerPatcher/queryversion.h diff --git a/ExplorerPatcher/ExplorerPatcher.vcxproj b/ExplorerPatcher/ExplorerPatcher.vcxproj index 4503f7b..915df97 100644 --- a/ExplorerPatcher/ExplorerPatcher.vcxproj +++ b/ExplorerPatcher/ExplorerPatcher.vcxproj @@ -213,7 +213,11 @@ true true - + + true + + + true true @@ -287,6 +291,7 @@ + diff --git a/ExplorerPatcher/ExplorerPatcher.vcxproj.filters b/ExplorerPatcher/ExplorerPatcher.vcxproj.filters index 6c4ba9a..a104f4c 100644 --- a/ExplorerPatcher/ExplorerPatcher.vcxproj.filters +++ b/ExplorerPatcher/ExplorerPatcher.vcxproj.filters @@ -105,6 +105,9 @@ Header Files\sws + + Header Files\internal + diff --git a/ExplorerPatcher/queryversion.h b/ExplorerPatcher/queryversion.h new file mode 100644 index 0000000..18b8061 --- /dev/null +++ b/ExplorerPatcher/queryversion.h @@ -0,0 +1,35 @@ +#ifndef _H_QUERYVERSION_H_ +#define _H_QUERYVERSION_H_ +#include +#pragma comment(lib, "Version.lib") + +inline void QueryVersionInfo(HMODULE hModule, WORD Resource, DWORD* dwLeftMost, DWORD* dwSecondLeft, DWORD* dwSecondRight, DWORD* dwRightMost) +{ + HRSRC hResInfo; + DWORD dwSize; + HGLOBAL hResData; + LPVOID pRes, pResCopy; + UINT uLen; + VS_FIXEDFILEINFO* lpFfi; + + hResInfo = FindResource(hModule, MAKEINTRESOURCE(Resource), RT_VERSION); + dwSize = SizeofResource(hModule, hResInfo); + hResData = LoadResource(hModule, hResInfo); + pRes = LockResource(hResData); + pResCopy = LocalAlloc(LMEM_FIXED, dwSize); + CopyMemory(pResCopy, pRes, dwSize); + FreeResource(hResData); + + VerQueryValue(pResCopy, TEXT("\\"), (LPVOID*)&lpFfi, &uLen); + + DWORD dwFileVersionMS = lpFfi->dwFileVersionMS; + DWORD dwFileVersionLS = lpFfi->dwFileVersionLS; + + *dwLeftMost = HIWORD(dwFileVersionMS); + *dwSecondLeft = LOWORD(dwFileVersionMS); + *dwSecondRight = HIWORD(dwFileVersionLS); + *dwRightMost = LOWORD(dwFileVersionLS); + + LocalFree(pResCopy); +} +#endif \ No newline at end of file diff --git a/ExplorerPatcher/utility.c b/ExplorerPatcher/utility.c index 3fc68b9..7c1f3ee 100644 --- a/ExplorerPatcher/utility.c +++ b/ExplorerPatcher/utility.c @@ -387,36 +387,6 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight, BOO return point; } -void QueryVersionInfo(HMODULE hModule, WORD Resource, DWORD* dwLeftMost, DWORD* dwSecondLeft, DWORD* dwSecondRight, DWORD* dwRightMost) -{ - HRSRC hResInfo; - DWORD dwSize; - HGLOBAL hResData; - LPVOID pRes, pResCopy; - UINT uLen; - VS_FIXEDFILEINFO* lpFfi; - - hResInfo = FindResource(hModule, MAKEINTRESOURCE(Resource), RT_VERSION); - dwSize = SizeofResource(hModule, hResInfo); - hResData = LoadResource(hModule, hResInfo); - pRes = LockResource(hResData); - pResCopy = LocalAlloc(LMEM_FIXED, dwSize); - CopyMemory(pResCopy, pRes, dwSize); - FreeResource(hResData); - - VerQueryValue(pResCopy, TEXT("\\"), (LPVOID*)&lpFfi, &uLen); - - DWORD dwFileVersionMS = lpFfi->dwFileVersionMS; - DWORD dwFileVersionLS = lpFfi->dwFileVersionLS; - - *dwLeftMost = HIWORD(dwFileVersionMS); - *dwSecondLeft = LOWORD(dwFileVersionMS); - *dwSecondRight = HIWORD(dwFileVersionLS); - *dwRightMost = LOWORD(dwFileVersionLS); - - LocalFree(pResCopy); -} - void* ReadFromFile(wchar_t* wszFileName, DWORD* dwSize) { void* ok = NULL; diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index 9b33431..7b84a22 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -14,6 +14,7 @@ #pragma comment(lib, "Rstrtmgr.lib") #define _LIBVALINET_INCLUDE_UNIVERSAL #include +#include "queryversion.h" #define APPID L"Microsoft.Windows.Explorer" #define REGPATH "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ExplorerPatcher" @@ -104,8 +105,6 @@ __declspec(dllexport) CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hIns POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight, BOOL bAdjust); -void QueryVersionInfo(HMODULE hModule, WORD Resource, DWORD*, DWORD*, DWORD*, DWORD*); - #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))