The MSDN entry for RegOpenKeyEx
also indicates that:
If the function fails, the return value is a nonzero error code defined in Winerror.h.
Those error codes are documented in MSDN - System Error Codes page. If you really are getting 7, then this error would correspond to:
ERROR_ARENA_TRASHED
7 (0x7)
The storage control blocks were destroyed.
What it means could range from your registry being corrupted, to a slew of program errors resulting in seemingly weird behavior, or to simply that you are getting something else as a return value and are lead to believe you are getting a result of 7. Without a more complete code example, it is hard to venture anything more specific.
P.S.: FormatMessage
is mostly handy if you are trying to obtain a string representation of the error at run time. If that's the case, you can refer to this answer for an example on how to use it.