Some time ago, I explained that the ERROR_
error code means that you tried to perform an operation on a deleted key. But what does it mean when you get the error when trying to create a key?
The key it’s complaining about is not the key you’re trying to create. The problem is with the key that you are trying to create the key beneath.
auto err = RegCreateKeyEx(parentKey, subkeyName,
0, nullptr, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &childKey);
If the parent key is deleted, then any future attempt to use that parent key (including creating child keys under it) will return ERROR_
.
We’ll look into this some more next time.
The same thing can happen with creating files or directories: if any parent directory in the path being created doesn't exist, then the syscall will fail with ENOENT (POSIX) / ERROR_PATH_NOT_FOUND (Windows). Windows at least has the two separate error codes ERROR_PATH_NOT_FOUND and ERROR_FILE_NOT_FOUND, so users can distinguish between parent directory not found vs. the leaf file not being found (for non-creating open dispositions), whereas POSIX makes no such distinction.