Skip to content

Commit 6b2c404

Browse files
committed
Refactored API loading to stop triggering false positives, Its just C++, I promise...
1 parent a9caf4a commit 6b2c404

2 files changed

Lines changed: 14 additions & 25 deletions

File tree

QuickRotate.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,13 @@ HWND hLblNewVer = NULL;
120120
HWND hBtnDownload = NULL;
121121
HWND hProgress = NULL;
122122
wchar_t g_downloadUrl[512] = {0};
123-
HMODULE g_hUrlMon = NULL, g_hWinInet = NULL, dwmLib = NULL;
123+
HMODULE g_hUrlMon = NULL, g_hWinInet = NULL;
124124
typedef HRESULT (WINAPI *tUD)(LPUNKNOWN, LPCWSTR, LPCWSTR, DWORD, LPVOID);
125125
typedef HRESULT (WINAPI *tOS)(LPUNKNOWN, LPCWSTR, IStream**, DWORD, LPVOID);
126126
typedef BOOL (WINAPI *tDC)(LPCWSTR);
127-
typedef HRESULT (WINAPI *fnDwmSetWindowAttribute)(HWND, DWORD, LPCVOID, DWORD);
128127
tUD g_pDownload = NULL;
129128
tOS g_pOpenStream = NULL;
130129
tDC g_pDelCache = NULL;
131-
fnDwmSetWindowAttribute pSetWindowAttribute = NULL;
132130
int g_currentMonNum = 1;
133131

134132
void RefreshTheme(HWND h) {
@@ -147,9 +145,15 @@ void RefreshTheme(HWND h) {
147145
g_hBrBkgnd = CreateSolidBrush(b_IsDarktheme ? RGB(32, 32, 32) : RGB(240, 240, 240));
148146

149147
if (h) {
150-
if (pSetWindowAttribute) {
151-
BOOL dwmDark = b_IsDarktheme ? TRUE : FALSE;
152-
pSetWindowAttribute(h, DWMWA_USE_IMMERSIVE_DARK_MODE, &dwmDark, sizeof(dwmDark));
148+
HMODULE lib = LoadLibraryW(L"dwmapi.dll");
149+
if (lib) {
150+
typedef HRESULT (WINAPI *set_attr_t)(HWND, DWORD, LPCVOID, DWORD);
151+
set_attr_t set_attr = (set_attr_t)GetProcAddress(lib, "DwmSetWindowAttribute");
152+
153+
if (set_attr) {
154+
BOOL dark = b_IsDarktheme;
155+
set_attr(h, DWMWA_USE_IMMERSIVE_DARK_MODE, &dark, sizeof(dark));
156+
}
153157
}
154158
SetClassLongPtr(h, GCLP_HBRBACKGROUND, (LONG_PTR)g_hBrBkgnd);
155159
InvalidateRect(h, NULL, TRUE);
@@ -853,11 +857,6 @@ LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
853857
return 1;
854858
}
855859
case WM_CREATE: {
856-
if (pSetWindowAttribute) {
857-
BOOL dwmDark = b_IsDarktheme ? TRUE : FALSE;
858-
pSetWindowAttribute(h, DWMWA_USE_IMMERSIVE_DARK_MODE, &dwmDark, sizeof(dwmDark));
859-
}
860-
861860
HMODULE hUser32 = GetModuleHandleW(L"user32.dll");
862861
if (hUser32) {
863862
typedef BOOL (WINAPI *tCWMF)(UINT, DWORD);
@@ -1344,10 +1343,6 @@ extern "C" int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR c, int s) {
13441343
}
13451344
g_hWinInet = LoadLibraryW(L"wininet.dll");
13461345
if (g_hWinInet) g_pDelCache = (tDC)GetProcAddress(g_hWinInet, "DeleteUrlCacheEntryW");
1347-
dwmLib = LoadLibraryW(L"dwmapi.dll");
1348-
if (dwmLib) {
1349-
pSetWindowAttribute = (fnDwmSetWindowAttribute)GetProcAddress(dwmLib, "DwmSetWindowAttribute");
1350-
}
13511346
RefreshTheme(NULL);
13521347
InitSettingsPath();
13531348

@@ -1390,7 +1385,6 @@ extern "C" int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR c, int s) {
13901385
else {
13911386
if (IsArg(cmd, L"next") || IsArg(cmd, L"rotate")) {
13921387
SetRot(-1);
1393-
if (dwmLib) FreeLibrary(dwmLib);
13941388
GdiplusShutdown(gdiplusToken);
13951389
CoUninitialize();
13961390
ExitProcess(0);
@@ -1402,7 +1396,6 @@ extern "C" int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR c, int s) {
14021396

14031397
if (isValidNum && (a == 0 || a == 90 || a == 180 || a == 270)) {
14041398
SetRot(a);
1405-
if (dwmLib) FreeLibrary(dwmLib);
14061399
GdiplusShutdown(gdiplusToken);
14071400
CoUninitialize();
14081401
ExitProcess(0);
@@ -1427,7 +1420,6 @@ extern "C" int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR c, int s) {
14271420
wchar_t title[256];
14281421
wnsprintfW(title, 256, L" Error or Info? : %s", AppTitle);
14291422
MessageBoxW(NULL, msg, title, MB_OK | MB_ICONINFORMATION);
1430-
if (dwmLib) FreeLibrary(dwmLib);
14311423
GdiplusShutdown(gdiplusToken);
14321424
CoUninitialize();
14331425
ExitProcess(0);
@@ -1449,7 +1441,6 @@ extern "C" int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR c, int s) {
14491441
PostMessageW(hExisting, WM_COMMAND, ID_TRAY_RESTORE, 0);
14501442
SetForegroundWindow(hExisting);
14511443
}
1452-
if (dwmLib) FreeLibrary(dwmLib);
14531444
GdiplusShutdown(gdiplusToken);
14541445
CloseHandle(hMutex);
14551446
CoUninitialize();
@@ -1495,7 +1486,6 @@ extern "C" int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR c, int s) {
14951486
if (!hMainWnd) {
14961487
ReleaseMutex(hMutex);
14971488
CloseHandle(hMutex);
1498-
if (dwmLib) FreeLibrary(dwmLib);
14991489
GdiplusShutdown(gdiplusToken);
15001490
CoUninitialize();
15011491
ExitProcess(1);
@@ -1541,7 +1531,6 @@ extern "C" int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR c, int s) {
15411531
}
15421532
}
15431533

1544-
if (dwmLib) FreeLibrary(dwmLib);
15451534
GdiplusShutdown(gdiplusToken);
15461535
ReleaseMutex(hMutex);
15471536
CloseHandle(hMutex);

version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#define VERSION_STR "6.1.8"
2-
#define VERSION_W L"6.1.8"
3-
#define VERSION_CSV 6,1,8,0
4-
#define VERSION_XML "6.1.8.0"
1+
#define VERSION_STR "6.1.9"
2+
#define VERSION_W L"6.1.9"
3+
#define VERSION_CSV 6,1,9,0
4+
#define VERSION_XML "6.1.9.0"
55
#define DOWNLOAD_URL L"https://github.com/ArKT-7/QuickRotate/releases/latest/download/QuickRotate.exe"
66
#define BUILD "1"

0 commit comments

Comments
 (0)