2016-06-16 12:59:54 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-16 12:59:54 +00:00
|
|
|
*/
|
|
|
|
#include "platform/win/windows_dlls.h"
|
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
#include "base/platform/win/base_windows_safe_library.h"
|
|
|
|
|
2019-06-03 10:48:36 +00:00
|
|
|
#include <VersionHelpers.h>
|
2018-07-28 10:50:28 +00:00
|
|
|
#include <QtCore/QSysInfo>
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
namespace Platform {
|
|
|
|
namespace Dlls {
|
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
using base::Platform::SafeLoadLibrary;
|
|
|
|
using base::Platform::LoadMethod;
|
2016-08-14 18:55:59 +00:00
|
|
|
|
|
|
|
void init() {
|
|
|
|
static bool inited = false;
|
|
|
|
if (inited) return;
|
|
|
|
inited = true;
|
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
// Remove the current directory from the DLL search order.
|
|
|
|
::SetDllDirectory(L"");
|
|
|
|
|
|
|
|
const auto list = {
|
|
|
|
u"dbghelp.dll"_q,
|
|
|
|
u"dbgcore.dll"_q,
|
|
|
|
u"propsys.dll"_q,
|
|
|
|
u"winsta.dll"_q,
|
|
|
|
u"textinputframework.dll"_q,
|
|
|
|
u"uxtheme.dll"_q,
|
|
|
|
u"igdumdim32.dll"_q,
|
|
|
|
u"amdhdl32.dll"_q,
|
|
|
|
u"wtsapi32.dll"_q,
|
|
|
|
u"propsys.dll"_q,
|
|
|
|
u"combase.dll"_q,
|
|
|
|
u"dwmapi.dll"_q,
|
|
|
|
u"rstrtmgr.dll"_q,
|
|
|
|
u"psapi.dll"_q,
|
2020-07-24 12:15:32 +00:00
|
|
|
u"user32.dll"_q,
|
2020-07-02 17:01:25 +00:00
|
|
|
};
|
|
|
|
for (const auto &lib : list) {
|
|
|
|
SafeLoadLibrary(lib);
|
2016-08-14 18:55:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
f_SetWindowTheme SetWindowTheme;
|
2020-07-24 12:15:32 +00:00
|
|
|
//f_RefreshImmersiveColorPolicyState RefreshImmersiveColorPolicyState;
|
|
|
|
//f_AllowDarkModeForApp AllowDarkModeForApp;
|
|
|
|
//f_SetPreferredAppMode SetPreferredAppMode;
|
|
|
|
//f_AllowDarkModeForWindow AllowDarkModeForWindow;
|
|
|
|
//f_FlushMenuThemes FlushMenuThemes;
|
2016-06-16 12:59:54 +00:00
|
|
|
f_OpenAs_RunDLL OpenAs_RunDLL;
|
|
|
|
f_SHOpenWithDialog SHOpenWithDialog;
|
|
|
|
f_SHAssocEnumHandlers SHAssocEnumHandlers;
|
|
|
|
f_SHCreateItemFromParsingName SHCreateItemFromParsingName;
|
|
|
|
f_WTSRegisterSessionNotification WTSRegisterSessionNotification;
|
|
|
|
f_WTSUnRegisterSessionNotification WTSUnRegisterSessionNotification;
|
|
|
|
f_SHQueryUserNotificationState SHQueryUserNotificationState;
|
2016-12-19 16:51:29 +00:00
|
|
|
f_SHChangeNotify SHChangeNotify;
|
2016-06-16 12:59:54 +00:00
|
|
|
f_SetCurrentProcessExplicitAppUserModelID SetCurrentProcessExplicitAppUserModelID;
|
|
|
|
f_RoGetActivationFactory RoGetActivationFactory;
|
|
|
|
f_WindowsCreateStringReference WindowsCreateStringReference;
|
|
|
|
f_WindowsDeleteString WindowsDeleteString;
|
|
|
|
f_PropVariantToString PropVariantToString;
|
2017-02-01 10:12:52 +00:00
|
|
|
f_PSStringFromPropertyKey PSStringFromPropertyKey;
|
2018-07-25 12:04:01 +00:00
|
|
|
f_DwmIsCompositionEnabled DwmIsCompositionEnabled;
|
2020-07-24 12:15:32 +00:00
|
|
|
f_DwmSetWindowAttribute DwmSetWindowAttribute;
|
2018-07-26 20:36:28 +00:00
|
|
|
f_RmStartSession RmStartSession;
|
|
|
|
f_RmRegisterResources RmRegisterResources;
|
|
|
|
f_RmGetList RmGetList;
|
|
|
|
f_RmShutdown RmShutdown;
|
|
|
|
f_RmEndSession RmEndSession;
|
2018-11-12 07:50:40 +00:00
|
|
|
f_GetProcessMemoryInfo GetProcessMemoryInfo;
|
2020-07-24 12:15:32 +00:00
|
|
|
f_SetWindowCompositionAttribute SetWindowCompositionAttribute;
|
2016-06-16 12:59:54 +00:00
|
|
|
|
|
|
|
void start() {
|
2016-08-14 18:55:59 +00:00
|
|
|
init();
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
const auto LibShell32 = SafeLoadLibrary(u"shell32.dll"_q);
|
|
|
|
LoadMethod(LibShell32, "SHAssocEnumHandlers", SHAssocEnumHandlers);
|
|
|
|
LoadMethod(LibShell32, "SHCreateItemFromParsingName", SHCreateItemFromParsingName);
|
|
|
|
LoadMethod(LibShell32, "SHOpenWithDialog", SHOpenWithDialog);
|
|
|
|
LoadMethod(LibShell32, "OpenAs_RunDLLW", OpenAs_RunDLL);
|
|
|
|
LoadMethod(LibShell32, "SHQueryUserNotificationState", SHQueryUserNotificationState);
|
|
|
|
LoadMethod(LibShell32, "SHChangeNotify", SHChangeNotify);
|
|
|
|
LoadMethod(LibShell32, "SetCurrentProcessExplicitAppUserModelID", SetCurrentProcessExplicitAppUserModelID);
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
const auto LibUxTheme = SafeLoadLibrary(u"uxtheme.dll"_q);
|
|
|
|
LoadMethod(LibUxTheme, "SetWindowTheme", SetWindowTheme);
|
2020-07-24 12:15:32 +00:00
|
|
|
//if (IsWindows10OrGreater()) {
|
|
|
|
// static const auto kSystemVersion = QOperatingSystemVersion::current();
|
|
|
|
// static const auto kMinor = kSystemVersion.minorVersion();
|
|
|
|
// static const auto kBuild = kSystemVersion.microVersion();
|
|
|
|
// if (kMinor > 0 || (kMinor == 0 && kBuild >= 17763)) {
|
|
|
|
// if (kBuild < 18362) {
|
|
|
|
// LoadMethod(LibUxTheme, "AllowDarkModeForApp", AllowDarkModeForApp, 135);
|
|
|
|
// } else {
|
|
|
|
// LoadMethod(LibUxTheme, "SetPreferredAppMode", SetPreferredAppMode, 135);
|
|
|
|
// }
|
|
|
|
// LoadMethod(LibUxTheme, "AllowDarkModeForWindow", AllowDarkModeForWindow, 133);
|
|
|
|
// LoadMethod(LibUxTheme, "RefreshImmersiveColorPolicyState", RefreshImmersiveColorPolicyState, 104);
|
|
|
|
// LoadMethod(LibUxTheme, "FlushMenuThemes", FlushMenuThemes, 136);
|
|
|
|
// }
|
|
|
|
//}
|
2016-08-14 22:53:47 +00:00
|
|
|
|
2019-06-03 10:48:36 +00:00
|
|
|
if (IsWindowsVistaOrGreater()) {
|
2020-07-02 17:01:25 +00:00
|
|
|
const auto LibWtsApi32 = SafeLoadLibrary(u"wtsapi32.dll"_q);
|
|
|
|
LoadMethod(LibWtsApi32, "WTSRegisterSessionNotification", WTSRegisterSessionNotification);
|
|
|
|
LoadMethod(LibWtsApi32, "WTSUnRegisterSessionNotification", WTSUnRegisterSessionNotification);
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
const auto LibPropSys = SafeLoadLibrary(u"propsys.dll"_q);
|
|
|
|
LoadMethod(LibPropSys, "PropVariantToString", PropVariantToString);
|
|
|
|
LoadMethod(LibPropSys, "PSStringFromPropertyKey", PSStringFromPropertyKey);
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2019-06-03 10:48:36 +00:00
|
|
|
if (IsWindows8OrGreater()) {
|
2020-07-02 17:01:25 +00:00
|
|
|
const auto LibComBase = SafeLoadLibrary(u"combase.dll"_q);
|
|
|
|
LoadMethod(LibComBase, "RoGetActivationFactory", RoGetActivationFactory);
|
|
|
|
LoadMethod(LibComBase, "WindowsCreateStringReference", WindowsCreateStringReference);
|
|
|
|
LoadMethod(LibComBase, "WindowsDeleteString", WindowsDeleteString);
|
2016-08-14 18:55:59 +00:00
|
|
|
}
|
2018-07-25 12:04:01 +00:00
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
const auto LibDwmApi = SafeLoadLibrary(u"dwmapi.dll"_q);
|
|
|
|
LoadMethod(LibDwmApi, "DwmIsCompositionEnabled", DwmIsCompositionEnabled);
|
2020-07-24 12:15:32 +00:00
|
|
|
LoadMethod(LibDwmApi, "DwmSetWindowAttribute", DwmSetWindowAttribute);
|
2018-07-26 20:36:28 +00:00
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
const auto LibRstrtMgr = SafeLoadLibrary(u"rstrtmgr.dll"_q);
|
|
|
|
LoadMethod(LibRstrtMgr, "RmStartSession", RmStartSession);
|
|
|
|
LoadMethod(LibRstrtMgr, "RmRegisterResources", RmRegisterResources);
|
|
|
|
LoadMethod(LibRstrtMgr, "RmGetList", RmGetList);
|
|
|
|
LoadMethod(LibRstrtMgr, "RmShutdown", RmShutdown);
|
|
|
|
LoadMethod(LibRstrtMgr, "RmEndSession", RmEndSession);
|
2016-08-14 18:55:59 +00:00
|
|
|
}
|
2018-11-12 07:50:40 +00:00
|
|
|
|
2020-07-02 17:01:25 +00:00
|
|
|
const auto LibPsApi = SafeLoadLibrary(u"psapi.dll"_q);
|
|
|
|
LoadMethod(LibPsApi, "GetProcessMemoryInfo", GetProcessMemoryInfo);
|
2020-07-24 12:15:32 +00:00
|
|
|
|
|
|
|
const auto LibUser32 = SafeLoadLibrary(u"user32.dll"_q);
|
|
|
|
LoadMethod(LibUser32, "SetWindowCompositionAttribute", SetWindowCompositionAttribute);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Dlls
|
|
|
|
} // namespace Platform
|