I uploaded on GitHub some C++ code of mine that wraps some Windows registry C-interface APIs, using RAII, STL classes like std::wstring and std::vector, and signals error conditions using exceptions.
Using these high-level C++ wrappers, you can easily access the Windows registry with simple code like this:
// Open a registry key
// Read a DWORD value
DWORD dw = key.GetDwordValue(L"MyValue1");
// Read a string value
wstring s = key.GetStringValue(L"MyValue2");
// Enumerate the values under the given key
auto values = key.EnumValues();
On the May issue of MSDN Magazine you’ll find an article describing some of the techniques applied in this code.
EDIT 2017-05-02: Added link to my MSDN Magazine article.
The March 2017 issue of MSDN Magazine contains a feature article of mine on simplifying safe array programming in C++ with the help of the ATL’s CComSafeArray class template.
There is also an accompanying web-only side bar introducing the SAFEARRAY C data structure and some of the basic operations available for it via Win32 API calls, although for C++ code I encourage the use of a convenient higher-level C++ object-oriented wrapper like ATL::CComSafeArray.
Safe arrays are useful for example when you have a COM component and you want to exchange array data between the component and its clients (that can be potentially written in languages even different than C++, e.g. C#, or scripting languages).
I wish I could have had such a resource available when I did some safe array programming in C++.
Some of the insights and experience I developed in that regard are distilled in the aforementioned article.
I hope it may be helpful to someone.
Check it out here!
Another C++ article of mine was published on MSDN Magazine (in the 2016 September issue):
“Unicode Encoding Conversions with STL Strings and Win32 APIs”
Check it out!
Thanks to my editor Sharon Terdeman for her excellent editing work, and to my tech reviewers David Cravey and Marc Gregoire for their useful suggestions and feedback.
EDIT (2016-SEP-02): A Visual Studio solution containing C++ code based on this article can be found on GitHub here.
My first article for MSDN Magazine is online! I’m excited about that. Crafting that article has been an interesting, fun and rewarding experience.
Using STL Strings at Win32 API Boundaries
I still recall when I was 20 years young, and used to visit a local newsstand looking forward to buy MSJ (Microsoft Systems Journal), later merged into MSDN Magazine, and delving into it.
I’d like to express my sincere gratitude to Stephan T. Lavavej for his thorough review, to David Cravey for his feedback, to my editor Sharon Terdeman for handling my article in a great way and for her excellent communication, and to Eric Battalio, Gordon Hogenson and MSDN Magazine editor-in-chief Michael Desmond for the initial contacts and for starting the process.
I hope you enjoy reading the article.