Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 有没有办法直接使用RegGetValue()检查注册表值的存在?_C++_Windows_Registry - Fatal编程技术网

C++ 有没有办法直接使用RegGetValue()检查注册表值的存在?

C++ 有没有办法直接使用RegGetValue()检查注册表值的存在?,c++,windows,registry,C++,Windows,Registry,有没有办法直接使用RegGetValue()检查注册表值的存在 RegGetValue()()的文档没有提到在缺少值的情况下会发生什么 REG\u NONE(无定义的值类型)类型是否表示缺少该值,还是仅表示该值具有未指定的类型 是调用RegEnumValue()并检查每个值名称的唯一选项吗 谢谢…如注释中所述,您需要检查函数的返回值。 在您的情况下,它将是这样的: DWORD dwErrorResult = RegGetValue(...); switch(dwErrorResult) { ca

有没有办法直接使用
RegGetValue()
检查注册表值的存在

RegGetValue()
()的文档没有提到在缺少值的情况下会发生什么

REG\u NONE
(无定义的值类型)类型是否表示缺少该值,还是仅表示该值具有未指定的类型

是调用
RegEnumValue()
并检查每个值名称的唯一选项吗

谢谢…

如注释中所述,您需要检查函数的返回值。 在您的情况下,它将是这样的:

DWORD dwErrorResult = RegGetValue(...);
switch(dwErrorResult)
{
case ERROR_SUCCESS:
    // Success -> means that the value is found and data is read
    break;
case ERROR_FILE_NOT_FOUND:
    // Value not found - you should do your thing here
    break;
case ERROR_MORE_DATA:
    // The buffer is too small to hold the value
    break;
case ERROR_INVALID_PARAMETER:
    // An invalid combination of flags was specified
    break;
default:
    // An unknown error occurred.
    break;
}

MSDN说“如果函数失败,返回值是系统错误代码。”代码可能是
error\u FILE\u NOT\u FOUND
或类似代码。但有1000多个代码。我们应该猜测并期待最好的结果吗?使用不存在的键名调用RegGetValue()的工作实现,这是要使用的错误代码。谢谢。如果我能自己找到这些信息那就太好了——你是通过实验知道的吗?你不需要猜。在大多数情况下,您只能与成功代码进行比较。在极少数情况下,您还可以将其与要单独处理的特定错误代码进行比较(例如“拒绝访问”)。