windows_dlls.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "platform/win/windows_dlls.h"
  8. #include "base/platform/win/base_windows_safe_library.h"
  9. #include "ui/gl/gl_detection.h"
  10. #include <VersionHelpers.h>
  11. #include <QtCore/QSysInfo>
  12. #define LOAD_SYMBOL(lib, name) ::base::Platform::LoadMethod(lib, #name, name)
  13. #ifdef DESKTOP_APP_USE_ANGLE
  14. bool DirectXResolveCompiler();
  15. #endif // DESKTOP_APP_USE_ANGLE
  16. namespace Platform {
  17. namespace Dlls {
  18. namespace {
  19. struct SafeIniter {
  20. SafeIniter();
  21. };
  22. SafeIniter::SafeIniter() {
  23. base::Platform::InitDynamicLibraries();
  24. const auto LibShell32 = LoadLibrary(L"shell32.dll");
  25. LOAD_SYMBOL(LibShell32, SHAssocEnumHandlers);
  26. LOAD_SYMBOL(LibShell32, SHCreateItemFromParsingName);
  27. LOAD_SYMBOL(LibShell32, SHOpenWithDialog);
  28. LOAD_SYMBOL(LibShell32, OpenAs_RunDLL);
  29. LOAD_SYMBOL(LibShell32, SHQueryUserNotificationState);
  30. LOAD_SYMBOL(LibShell32, SHChangeNotify);
  31. //if (IsWindows10OrGreater()) {
  32. // static const auto kSystemVersion = QOperatingSystemVersion::current();
  33. // static const auto kMinor = kSystemVersion.minorVersion();
  34. // static const auto kBuild = kSystemVersion.microVersion();
  35. // if (kMinor > 0 || (kMinor == 0 && kBuild >= 17763)) {
  36. // const auto LibUxTheme = LoadLibrary(L"uxtheme.dll");
  37. // if (kBuild < 18362) {
  38. // LOAD_SYMBOL(LibUxTheme, AllowDarkModeForApp, 135);
  39. // } else {
  40. // LOAD_SYMBOL(LibUxTheme, SetPreferredAppMode, 135);
  41. // }
  42. // LOAD_SYMBOL(LibUxTheme, AllowDarkModeForWindow, 133);
  43. // LOAD_SYMBOL(LibUxTheme, RefreshImmersiveColorPolicyState, 104);
  44. // LOAD_SYMBOL(LibUxTheme, FlushMenuThemes, 136);
  45. // }
  46. //}
  47. const auto LibPropSys = LoadLibrary(L"propsys.dll");
  48. LOAD_SYMBOL(LibPropSys, PSStringFromPropertyKey);
  49. const auto LibPsApi = LoadLibrary(L"psapi.dll");
  50. LOAD_SYMBOL(LibPsApi, GetProcessMemoryInfo);
  51. const auto LibUser32 = LoadLibrary(L"user32.dll");
  52. LOAD_SYMBOL(LibUser32, SetWindowCompositionAttribute);
  53. const auto LibShCore = LoadLibrary(L"Shcore.dll");
  54. LOAD_SYMBOL(LibShCore, GetDpiForMonitor);
  55. }
  56. SafeIniter kSafeIniter;
  57. } // namespace
  58. void CheckLoadedModules() {
  59. #ifdef DESKTOP_APP_USE_ANGLE
  60. if (DirectXResolveCompiler()) {
  61. auto LibD3DCompiler = HMODULE();
  62. if (GetModuleHandleEx(0, L"d3dcompiler_47.dll", &LibD3DCompiler)) {
  63. constexpr auto kMaxPathLong = 32767;
  64. auto path = std::array<WCHAR, kMaxPathLong + 1>{ 0 };
  65. const auto length = GetModuleFileName(
  66. LibD3DCompiler,
  67. path.data(),
  68. kMaxPathLong);
  69. if (length > 0 && length < kMaxPathLong) {
  70. LOG(("Using DirectX compiler '%1'."
  71. ).arg(QString::fromWCharArray(path.data())));
  72. } else {
  73. LOG(("Error: Could not resolve DirectX compiler path."));
  74. }
  75. } else {
  76. LOG(("Error: Could not resolve DirectX compiler module."));
  77. }
  78. } else {
  79. LOG(("Error: Could not resolve DirectX compiler library."));
  80. }
  81. #endif // DESKTOP_APP_USE_ANGLE
  82. }
  83. } // namespace Dlls
  84. } // namespace Platform