CRegKey Registry Class

When trying to add registry functionality to a MFC application that I was developing, I looked up CReg* in the Win32 helpfile and sure enough found a CRegKey class. Great! Until you try and use this class in a non ATL (Active Template Library) application, as this code "depends" upon it.

So I went looking at the original source code to see what could possibly be


ATL dependant about the CRegKey registry class, and the answer was- nothing!

So where does the CRegKey class live?

Answer:

Header file:


..vcatlincludeatlbase.h


Source file:


..vcatlincludeatlimpl.cpp

After removing just the CRegKey code from both the source code and header file, I was able to add the class to my own projects and use it without problem.

The only “advantage” of this code is that it has already been written by Microsoft, so hopefully debugging it would not be an option (I did say hopefully 😉 ). So far it seems to work perfectly without any problems, and lets face it, its not a huge stack of code.

I have posted this discovery because after looking at several newsnet articles, different people had different ideas about how to get the CRegKey class working, but nobody actually suggested just cutting away the code that does the hard work. However, I do fully appreciate that other people may have already written their own classes that may have more functionality.

Download source – 2KB

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read