何判断哪个值触发了RegNotifyChangeKeyValue

何判断哪个值触发了RegNotifyChangeKeyValue

本文介绍了如何判断哪个值触发了RegNotifyChangeKeyValue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 API来跟踪更改到我的注册表项和C ++示例类似于MSDN页面底部给出的。我这样设置此API:

  RegOpenKeyEx(HKEY_LOCAL_MACHINE,LSoftware \\ Company \\Product 0,KEY_NOTIFY,& hKey); 
RegNotifyChangeKeyValue(hKey,FALSE,REG_NOTIFY_CHANGE_LAST_SET,hEvent,TRUE);

因此,例如,当这个API接受的事件作为参数时,到 Software \Company \Product 键)有没有办法找出哪个值实际触发了它?

解决方案

否。您需要在调用RegNotifyChangeKeyValue后缓存当前的名称/值对,然后在发出信号时,您可以将最新的名称/值对与您的缓存进行比较,看看有什么不同,然后更新下一个信号的缓存。 p>

如果在RegNotifyChangeKeyValue调用之前构建缓存,并且两个操作之间的某个线程进行了更新,那么缓存不会反映实际状态,并且可能导致问题



在RegNotifyChangeKeyValue之后构建缓存可能会导致您的代码发出信号,但无法知道什么值(如果更新是由两个操作之间的另一个线程进行的)。没什么大不了的:只是假装没有任何改变。


I am using RegNotifyChangeKeyValue API to track changes to my registry key and the C++ example similar to the one given at the bottom of that MSDN page. I set this API as such:

RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Company\\Product", 0, KEY_NOTIFY, &hKey);
RegNotifyChangeKeyValue(hKey, FALSE, REG_NOTIFY_CHANGE_LAST_SET, hEvent, TRUE);

So, say, when the event that this API takes as a parameters is signaled (which means a change to the Software\Company\Product key) is there any way to find out which value actually triggered it?

解决方案

No. You need to cache the current name/value pairs AFTER the call to RegNotifyChangeKeyValue, and then when signaled you can compare the latest name/value pairs to your cache to see what is different, and then update your cache for the next signal.

If you build your cache BEFORE the RegNotifyChangeKeyValue call, and an update is made by some thread between the two operations, your cache will NOT reflect the actual state, and that MAY cause problems on the next update (depending on your needs).

Building the cache AFTER the RegNotifyChangeKeyValue MAY cause your code being signaled but being unable to know what value is concerned (if the update is made by another thread between the two operations). No big deal: just pretend to not seing any change.

这篇关于如何判断哪个值触发了RegNotifyChangeKeyValue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:03