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

时间:2016-03-10 11:25:11

标签: c++ windows registry

  

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

RegGetValue()https://msdn.microsoft.com/da-dk/library/windows/desktop/ms724868(v=vs.85).aspx)的文档并未提及在缺少值时会发生什么。

某种类型的REG_NONE没有定义的值类型)是否表示该值缺失,或者它是否仅表示该值具有未指定的类型?

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

...谢谢

1 个答案:

答案 0 :(得分:2)

作为评论中陈述的Roman R.,您需要检查函数的返回值。 在你的情况下,它将是这样的:

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;
}