It would be good to know what is not working.
First, read the documentation of the used functions.
Then check the return value of each function call and report the error code (at least in debug builds to be detected during development):
LONG err = reg.Create(m_hKeyParent,m_myKey);
if (ERROR_SUCCESS != err)
{
}
I have not tested the code but assume that this fails with an invalid handle error. See
CRegKey::Create[
^]. The
hKeyParent
parameter muste be a handle of an
open key.
But there is no need to create the key. Just use
Open()
because it will create the key if it does note exist yet:
LONG err = reg.Open(HKEY_CURRENT_USER, L"Software\\MyRegDemo");
if (ERROR_SUCCESS != err)
{
}
else
{
reg.Close();
}
When reading a boolean value stored in a DWORD, a zero value should be interpreted as
FALSE
and non-zero as
TRUE
. It is common to write a '1' for
TRUE
but some write also the value with all bits set.
So you should always check for zero / non-zero when reading such values:
DWORD dvalue = 0;
m_chkbox1.SetCheck(dvalue != 0);
Note that I have initialised
dvalue
in the above example. While this should be always done, it is important here when your program is executed the first time because the value does not exist yet (it is created when leaving your program).