MCPcopy Create free account
hub / github.com/TranslucentTB/TranslucentTB / DynamicLoader

Class DynamicLoader

TranslucentTB/dynamicloader.hpp:12–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "../ProgramLog/error/win32.hpp"
11
12class DynamicLoader {
13 wil::unique_hmodule m_User32, m_UxTheme;
14
15 PFN_SHOULD_SYSTEM_USE_DARK_MODE m_Ssudm = nullptr;
16
17public:
18 inline DynamicLoader()
19 {
20 m_User32.reset(LoadLibraryEx(L"user32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32));
21 if (!m_User32) [[unlikely]]
22 {
23 LastErrorHandle(spdlog::level::critical, L"Failed to load user32.dll");
24 }
25
26 m_UxTheme.reset(LoadLibraryEx(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32));
27 if (m_UxTheme)
28 {
29 m_Ssudm = reinterpret_cast<PFN_SHOULD_SYSTEM_USE_DARK_MODE>(GetProcAddress(m_UxTheme.get(), MAKEINTRESOURCEA(138)));
30 if (!m_Ssudm) [[unlikely]]
31 {
32 LastErrorHandle(spdlog::level::warn, L"Failed to get address of ShouldSystemUseDarkMode");
33 }
34 }
35 else
36 {
37 LastErrorHandle(spdlog::level::warn, L"Failed to load uxtheme.dll");
38 }
39 }
40
41 DynamicLoader(const DynamicLoader &) = delete;
42 DynamicLoader &operator =(const DynamicLoader &) = delete;
43
44 // Stored by TaskbarAttributeWorker, but only 1 instance
45 inline PFN_SET_WINDOW_COMPOSITION_ATTRIBUTE SetWindowCompositionAttribute() const
46 {
47 const auto fn = reinterpret_cast<PFN_SET_WINDOW_COMPOSITION_ATTRIBUTE>(GetProcAddress(m_User32.get(), UTIL_STRINGIFY_UTF8(SetWindowCompositionAttribute)));
48 if (!fn) [[unlikely]]
49 {
50 LastErrorHandle(spdlog::level::critical, L"Failed to get address of SetWindowCompositionAttribute");
51 }
52
53 return fn;
54 }
55
56 // Used in Application constructor
57 inline PFN_SET_PREFERRED_APP_MODE SetPreferredAppMode() const
58 {
59 if (m_UxTheme)
60 {
61 const auto fn = reinterpret_cast<PFN_SET_PREFERRED_APP_MODE>(GetProcAddress(m_UxTheme.get(), MAKEINTRESOURCEA(135)));
62 if (!fn) [[unlikely]]
63 {
64 LastErrorHandle(spdlog::level::warn, L"Failed to get address of SetPreferredAppMode");
65 }
66
67 return fn;
68 }
69 else

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected