Building the Right Environment to Support AI, Machine Learning and Deep Learning
I personally find the Win32 Registry API to be overly complex for performing simple operations. The Win32 Registry API is very "rich". You can do a lot with it, but most of the time you just want to read or write a value. The error checking involved in doing even simple registry operations is enough to hide the meaning of the code. Most of the time you either want the operation to succeed or fail as a whole, you're not interested in handling errors at each stage and performing recovery operations...
CRegistryKey is essentially just a very simple wrapper around a HKEY. It adds value by converting errors to exceptions, defaulting most of the rarely used parameters with sensible values and providing STL style iterators for sub keys and values. All of the Win32 Registry API is present as member functions, but if you want to check for errors without using exceptions there's a conversion operator that will allow access to the underlying HKEY.
CRegistryKey was designed to make code like this as easy as possible...
CRegistryKey key = CRegistryKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE"));
// for each sub key of this key...
for (CRegistryKey::SubkeyIterator it = key.BeginSubkeyIteraton();
it != key.EndSubkeyIteraton();
// Dump out the key's name
tcout << it.GetName() << endl;
// Then display each value
CRegistryKey subKey = it.OpenKey();
for (CRegistryKey::ValueIterator val = subKey.BeginValueIteration();
val != subKey.EndValueIteration();
tcout << " " << val.name() << T(" ") << val.valueAsString() << endl;
catch (CRegistryKey::Exception &e)
So that this article and code can be kept up to date more easily I've provided a link to where the article is located on my own web pages. Read the full article and download the source code.
Last updated: 3 July 1998