C++ WinReg Library Updated with Contains Methods

I added a few convenient methods to my C++ WinReg library to test if a key contains specific values and sub-keys.

I just wanted to let you know that I updated my C++ WinReg library adding a few methods to test if a registry key contains a given value or a sub-key.

For example, now you can easily check if a key contains a value with some simple C++ code like this:

// 'key' is an instance of the winreg::RegKey class.
// Check if the given key contains a value named "Connie":
if (key.ContainsValue(L"Connie"))
{
    // The value is in the key...
}

From an implementation point of view, the RegKey::ContainsValue method invokes the RegGetValueW Win32 API, and checks its return code.

If the return code is ERROR_SUCCESS (0), the value was found in the key, and the method returns true.

If the return code is ERROR_FILE_NOT_FOUND (2), it means that there is no value with that given name in the key, so the method returns false.

In all other cases, an exception is thrown.

There is a similar method to check for sub-keys, named ContainsSubKey. And there are also the non-exception forms TryContainsValue and TryContainsSubKey.

Leave a comment