0

We are trying to determine if auto rotation is currently enabled or disabled from our c++ application. The following code always returns a value of 1 even if regedit of the same key shows 0. It returns the same if the application is run as a standard user or as an administrator.

HKEY hkMain;
LONG lRes =  RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AutoRotation",0,KEY_QUERY_VALUE,&hkMain);
if (lRes==ERROR_SUCCESS) {
    DWORD dwRegValue=0,dwSize=0,dwType=0;
    dwSize = sizeof(DWORD);
    lRes = RegQueryValueEx(hkMain,TEXT("Enable"),NULL,&dwType,(LPBYTE)&dwRegValue,&dwSize);

    if (lRes==ERROR_SUCCESS) {
        // dwRegValue value is always 1
    }
    RegCloseKey(hkMain);
}
4

1 回答 1

0

Hans Passant 的评论提供了答案“您可能正在使用 Regedit 查找错误的密钥。导航到 SOFTWARE\Wow6432Node\Microsoft... 而不是在 64 位操作系统上。这是 32 位程序读取密钥的所在地。”我们需要在我们的注册表函数调用中包含 KEY_WOW64_64KEY 标志。谢谢

于 2013-02-11T13:46:12.200 回答