views:

399

answers:

2

The MSDN documentation:

http://msdn.microsoft.com/en-us/library/ms724897(VS.85).aspx

Is strangely silent on what errors this function might return.

I'm particularly interested in what error code is returned if the key doesn't exist, but more comprehensive information would be nice too.

+1  A: 

Why don't you simply try it and see in the debugger what it returns?

In the Visual Studio debugger you can simply enter

$err

to see the error code of the last executed function, and

$err,hr

to see the last error in full text.

Patrick
Certainly I can do that (and I did just do it... ERROR_FILE_NOT_FOUND is returned). However, I was hopeful that a better reference than the MSDN non-list could end up here to help anyone who looks for the same thing in the future.
gdunbar
+1  A: 

This is a standard Win32 kernel error code. The kind of code that GetLastError() returns, so the set of possible values can be found in WinError.h. Note that these are not HRESULT values.

//  The configuration registry database is corrupt.
//
#define ERROR_BADDB                      1009L

//  The configuration registry key is invalid.
//
#define ERROR_BADKEY                     1010L

//  The configuration registry key could not be opened.
//
#define ERROR_CANTOPEN                   1011L

//  The configuration registry key could not be read.
//
#define ERROR_CANTREAD                   1012L

//  The configuration registry key could not be written.
//
#define ERROR_CANTWRITE                  1013L

//  One of the files in the registry database had to be recovered by use of a log or alternate copy. The recovery was successful.
//
#define ERROR_REGISTRY_RECOVERED         1014L

//  The registry is corrupted. The structure of one of the files containing registry data is corrupted, or the system's memory image of the file is corrupted, or the file could not be recovered because the alternate copy or log was absent or corrupted.
//
#define ERROR_REGISTRY_CORRUPT           1015L

//  An I/O operation initiated by the registry failed unrecoverably. The registry could not read in, or write out, or flush, one of the files that contain the system's image of the registry.
//
#define ERROR_REGISTRY_IO_FAILED         1016L

//  The system has attempted to load or restore a file into the registry, but the specified file is not in a registry file format.
//
#define ERROR_NOT_REGISTRY_FILE          1017L

//  Illegal operation attempted on a registry key that has been marked for deletion.
//
#define ERROR_KEY_DELETED                1018L

//  System could not allocate the required space in a registry log.
//
#define ERROR_NO_LOG_SPACE               1019L

//  Cannot create a symbolic link in a registry key that already has subkeys or values.
//
#define ERROR_KEY_HAS_CHILDREN           1020L

//  Cannot create a stable subkey under a volatile parent key.
//
#define ERROR_CHILD_MUST_BE_VOLATILE     1021L

A comprehensive list of possible error codes from RegOpenKeyEx would be quite large and likely to change with each version of Windows, You should be prepared to handle any Win32 error code.

Edit: Apparently the error for a non-existent key is ERROR_FILE_NOT_FOUND.

John Knoeller
While the information is helpful, the list of registry errors there is a reference for what actually gets returned. Opening a non-existent key (HKCU\"SoftwareX" is what I used), returns 2, or ERROR_FILE_NOT_FOUND.
gdunbar