I have an activex control that I display in a webbrowser control on a windows mobile device using a C# forms app.
The activex control is working. I want to add a feature to the activex control where an event is raised in the activex control when a registry value changes state.
I have implemented the same (but reversed) functionality on the forms side using RegistryState with the following code. With this code my .net forms app gets notified when a registry value changes. The forms code is below.
private void TestContainer_Load(object sender, EventArgs e)
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey("MyKey");
state = new RegistryState("HKEY_LOCAL_MACHINE\\MyKey", "MessageToHostForm");
state.Changed += new ChangeEventHandler(state_Changed);
}
void state_Changed(object sender, ChangeEventArgs args)
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey("MyKey");
if (rk == null)
{
// No value available in the created/opened subkey
}
else
{
string strOut = (string)rk.GetValue("MessageToHostForm");
button3.Text = strOut;
rk.Close();
}
}
I would like to create the same functionality in the ActiveX control where an event in the control gets fired when a registry value changes.
The problen is … from what I can tell … Registry.State is not available in an ATL C++ app 🙁
How can I make my ATL ActiveX control respond to changes in registry values. (I don’t want to use polling)
Is this posible?
Thanks for at least reading this… Long I know…
To avoid polling, you can use CRegKey::NotifyChangeKeyValue, which is in turn built on top of
RegNotifyChangeKeyValue. You can have an event signaled with a change under the key. So your worker thread might be waiting for this event [possibly among others] and once your wait is satisfied you would do whatever you do in yourstate_Changedabove.You also have sample code there: http://msdn.microsoft.com/en-us/library/ms724892%28VS.85%29.aspx
UPD. I realized mobile platform is in question – things are somewhat different there, but still you have an event based option:
CeFindFirstRegChangehttp://msdn.microsoft.com/en-us/library/aa914423.aspx