0

I am trying to code simple program in C which writes and reads something from Windows registry. What does the return value of 7 for RegOpenKeyEx mean?

I am having a hard time trying to guess it. Yes, MSDN says I can use FormatMessage to examine it, but it takes 7 arguments and I have no idea how to use it... (what an awful api design by the way).

michailgames
  • 303
  • 2
  • 7
  • Yes, that's a badly designed API. The system error codes are documented on [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx). Btw, does it really return 7? – cremno Mar 15 '15 at 19:15
  • 1
    MSDN also says "If the function fails, the return value is a nonzero error code defined in Winerror.h", which you can get a description from [MSDN - System Error Codes](https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx). If you really are getting 7, this corresponds to `ERROR_ARENA_TRASHED`. – SleuthEye Mar 15 '15 at 19:17
  • `ERROR_ARENA_TRASHED` is rather implausible. MCVE please. – David Heffernan Mar 15 '15 at 19:48
  • Most error codes can be checked using `net helpmsg`, e.g., `net helpmsg 7` – Harry Johnston Mar 15 '15 at 21:59
  • Another helpful way to turn error messages into human readable form is to use the debugger. Type `7,hr` into the watch window and it will display its string representation. Not applicable here, but the return value of `GetLastError` is supported by the pseudo-variable `@err`. So if you type `@err,hr` into the watch window, you have a convenient way to analyze errors. – IInspectable Mar 15 '15 at 23:01

1 Answers1

1

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.

Community
  • 1
  • 1
SleuthEye
  • 14,379
  • 2
  • 32
  • 61