ModuleLoader.h
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 #pragma once 6 7 #include <Windows.h> 8 #include <string> 9 #include <vector> 10 #include <powertoy_module_interface.h> 11 12 /// <summary> 13 /// Wrapper class for loading and managing a PowerToy module DLL 14 /// </summary> 15 class ModuleLoader 16 { 17 public: 18 ModuleLoader(); 19 ~ModuleLoader(); 20 21 // Prevent copying 22 ModuleLoader(const ModuleLoader&) = delete; 23 ModuleLoader& operator=(const ModuleLoader&) = delete; 24 25 /// <summary> 26 /// Load a PowerToy module DLL 27 /// </summary> 28 /// <param name="dllPath">Path to the module DLL</param> 29 /// <returns>True if successful, false otherwise</returns> 30 bool Load(const std::wstring& dllPath); 31 32 /// <summary> 33 /// Enable the loaded module 34 /// </summary> 35 void Enable(); 36 37 /// <summary> 38 /// Disable the loaded module 39 /// </summary> 40 void Disable(); 41 42 /// <summary> 43 /// Check if the module is enabled 44 /// </summary> 45 /// <returns>True if enabled, false otherwise</returns> 46 bool IsEnabled() const; 47 48 /// <summary> 49 /// Set configuration for the module 50 /// </summary> 51 /// <param name="configJson">JSON configuration string</param> 52 void SetConfig(const std::wstring& configJson); 53 54 /// <summary> 55 /// Get the module's localized name 56 /// </summary> 57 /// <returns>Module name</returns> 58 std::wstring GetModuleName() const; 59 60 /// <summary> 61 /// Get the module's non-localized key 62 /// </summary> 63 /// <returns>Module key</returns> 64 std::wstring GetModuleKey() const; 65 66 /// <summary> 67 /// Get the module's hotkeys 68 /// </summary> 69 /// <param name="buffer">Buffer to store hotkeys</param> 70 /// <param name="bufferSize">Size of the buffer</param> 71 /// <returns>Number of hotkeys returned</returns> 72 size_t GetHotkeys(PowertoyModuleIface::Hotkey* buffer, size_t bufferSize); 73 74 /// <summary> 75 /// Trigger a hotkey callback on the module 76 /// </summary> 77 /// <param name="hotkeyId">ID of the hotkey to trigger</param> 78 /// <returns>True if the key press should be swallowed</returns> 79 bool OnHotkey(size_t hotkeyId); 80 81 /// <summary> 82 /// Check if the module is loaded 83 /// </summary> 84 /// <returns>True if loaded, false otherwise</returns> 85 bool IsLoaded() const { return m_module != nullptr; } 86 87 /// <summary> 88 /// Get the module's activation hotkey (newer HotkeyEx API) 89 /// </summary> 90 /// <returns>Optional HotkeyEx struct</returns> 91 std::optional<PowertoyModuleIface::HotkeyEx> GetHotkeyEx(); 92 93 /// <summary> 94 /// Trigger the newer-style hotkey callback on the module 95 /// </summary> 96 void OnHotkeyEx(); 97 98 private: 99 HMODULE m_hModule; 100 PowertoyModuleIface* m_module; 101 std::wstring m_dllPath; 102 };