If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Have you tried that?

And where you've put this

Code:

RegCloseKey(hKey);

it's utterly pointless as you've returned from the function. I'm surprised you don't get at least a warning for unreachable code on that.