Windows registry function SetValue invalidates handle

Trying to reuse the handle in other registry functions returns ERROR_INVALID_HANDLE. Close the handle and open a new one with the parameters you opened the original one with. Then try to use that one. That should work.