@@ -62,8 +62,11 @@ WindowsAPILayerStore::WindowsAPILayerStore(
6262 mKey = {};
6363 return ;
6464 }
65- mEvent .reset (CreateEvent (nullptr , false , false , nullptr ));
66- this ->WindowsAPILayerStore ::Poll ();
65+
66+ mWatcher = wil::make_registry_watcher (
67+ mKey .get (), /* no subkey. nullptr not allowed */ L" " , true , [this ](auto ) {
68+ this ->NotifyChange ();
69+ });
6770}
6871
6972WindowsAPILayerStore::~WindowsAPILayerStore () = default ;
@@ -136,13 +139,6 @@ std::vector<APILayer> WindowsAPILayerStore::GetAPILayers() const noexcept {
136139 return layers;
137140}
138141
139- bool WindowsAPILayerStore::Poll () const noexcept {
140- const auto result = WaitForSingleObject (mEvent .get (), 0 );
141- RegNotifyChangeKeyValue (
142- mKey .get (), false , REG_NOTIFY_CHANGE_LAST_SET, mEvent .get (), true );
143- return (result == WAIT_OBJECT_0);
144- }
145-
146142class ReadOnlyWindowsAPILayerStore final : public WindowsAPILayerStore {
147143 public:
148144 ReadOnlyWindowsAPILayerStore (
@@ -229,26 +225,26 @@ class ReadWriteWindowsAPILayerStore final : public WindowsAPILayerStore,
229225};
230226
231227template <class TInterface , class TConcrete >
232- std::span<const TInterface*> GetStaticStores () noexcept {
228+ std::span<TInterface*> GetStaticStores () noexcept {
233229 using RB = WindowsAPILayerStore::RegistryBitness;
234230 using enum APILayer::Kind;
235- static const TConcrete sHKLM64 {
231+ static TConcrete sHKLM64 {
236232 " Win64-HKLM" , Implicit, RB::Wow64_64, HKEY_LOCAL_MACHINE};
237- static const TConcrete sHKCU64 {
233+ static TConcrete sHKCU64 {
238234 " Win64-HKCU" , Implicit, RB::Wow64_64, HKEY_CURRENT_USER};
239- static const TConcrete sHKLM32 {
235+ static TConcrete sHKLM32 {
240236 " Win32-HKLM" , Implicit, RB::Wow64_32, HKEY_LOCAL_MACHINE};
241- static const TConcrete sHKCU32 {
237+ static TConcrete sHKCU32 {
242238 " Win32-HKCU" , Implicit, RB::Wow64_32, HKEY_CURRENT_USER};
243- static const TConcrete sExplicitHKLM64 {
239+ static TConcrete sExplicitHKLM64 {
244240 " Explicit Win64-HKLM" , Explicit, RB::Wow64_64, HKEY_LOCAL_MACHINE};
245- static const TConcrete sExplicitHKCU64 {
241+ static TConcrete sExplicitHKCU64 {
246242 " Explicit Win64-HKCU" , Explicit, RB::Wow64_64, HKEY_CURRENT_USER};
247- static const TConcrete sExplicitHKLM32 {
243+ static TConcrete sExplicitHKLM32 {
248244 " Explicit Win32-HKLM" , Explicit, RB::Wow64_32, HKEY_LOCAL_MACHINE};
249- static const TConcrete sExplicitHKCU32 {
245+ static TConcrete sExplicitHKCU32 {
250246 " Explicit Win32-HKCU" , Explicit, RB::Wow64_32, HKEY_CURRENT_USER};
251- static const TInterface* sStores [] {
247+ static TInterface* sStores [] {
252248 &sHKLM64 ,
253249 &sHKCU64 ,
254250 &sHKLM32 ,
@@ -261,12 +257,11 @@ std::span<const TInterface*> GetStaticStores() noexcept {
261257 return sStores ;
262258}
263259
264- std::span<const APILayerStore*> APILayerStore::Get () noexcept {
260+ std::span<APILayerStore*> APILayerStore::Get () noexcept {
265261 return GetStaticStores<APILayerStore, ReadOnlyWindowsAPILayerStore>();
266262};
267263
268- std::span<const ReadWriteAPILayerStore*>
269- ReadWriteAPILayerStore::Get () noexcept {
264+ std::span<ReadWriteAPILayerStore*> ReadWriteAPILayerStore::Get () noexcept {
270265 return GetStaticStores<
271266 ReadWriteAPILayerStore,
272267 ReadWriteWindowsAPILayerStore>();
0 commit comments