Nearly . RegCreateKeyEx has a double purpose. If the subkey already exists, it opens it. Whether the key pre-exists or not, it returns a handle to it. The branch to the subkey is created automatically.

Typically, to create a value, irrespective of whether you know it already exists, you'd do: RegCreateKeyEx > RegOpenKeyEx > RegSetValueEx > RegCloseKey.

To read a value, irrespective of whether you know it already exists, you'd do: RegOpenKeyEx > RegQueryValueEx (to get the type of data) > RegQueryValueEx (to get the actual data) > RegCloseKey. And return a default value or error code if RegOpenKeyEx or the first RegQueryValueEx failed.

If you're feeling lazy , search my previous posts using the above function names as keywords.