none
How to use "NKRegQueryValueEx" on "OALIoCtlHalInitRegistry". RRS feed

  • Question

  • Hi all.

    When I use the "NKRegQueryValueEx" function on the "OALIoCtlHalInitRegistry", "NKRegQueryValueEx" function return "ERROR_FILE_NOT_FOUND" error.

    My test code is like below :

    static BOOL GetRegDwordValue (LPCWSTR wszKeyPath, LPCWSTR wszKeyName, DWORD *dwValue) {
    HKEY hKey;
    UINT32 value;
    DWORD size = sizeof(DWORD);
    DWORD type = REG_DWORD;
    LONG lregreturn = 0;
    lregreturn = NKRegCreateKeyEx(HKEY_LOCAL_MACHINE, wszKeyPath, 0, NULL, 0, 0, NULL,&hKey, &value);
    if (lregreturn != ERROR_SUCCESS ) {
    RETAILMSG(1, (_T("[OAL] Failed to NKRegCreateKeyEx(%#X : %s)\r\n"), lregreturn, wszKeyPath));
        return FALSE;
    }

    lregreturn = NKRegQueryValueEx(hKey, wszKeyName, 0, &type, (LPBYTE)dwValue, &size);
    if (lregreturn != ERROR_SUCCESS) {
    RETAILMSG(1, (_T("[OAL] Failed to NKRegQueryValueEx(%#X : %s)\r\n"), lregreturn, wszKeyPath));
    NKRegCloseKey(hKey);
        return FALSE;
    }
    NKRegCloseKey(hKey);
    return TRUE;
    }

    error message : Failed to NKRegQueryValueEx(0X2 : Drivers\BuiltIn\Camera)

    I did use the "NKRegSetValueEx" On the same scope but "NKRegSetValueEx" function work fine.

    If anyone have to above case, please advice to me.



    • Edited by Jin.Lee Thursday, August 21, 2014 7:49 AM
    Thursday, August 21, 2014 7:44 AM

All replies

  • Your code contained quite a few problems. Try to improve on your coding standard. It will make you more precise and will result in much less errors.

    I've rewritten your code for you as an example:

    static BOOL GetRegDwordValue(LPCWSTR pszKeyPath, LPCWSTR pszKeyName, LPDWORD pdwValue)
    {
        HKEY hKey = NULL;
        DWORD dwSize;
        DWORD dwDisp;
        DWORD dwType;
        DWORD dwError = ERROR_SUCCESS;
        BOOL bRet = FALSE;
    
        for (;;)
        {   // Use for-loop for easy break out error handling
            dwError = NKRegCreateKeyEx(HKEY_LOCAL_MACHINE, pszKeyPath, 0, NULL, 0, 0, NULL, &hKey, &dwDisp);
            if (ERROR_SUCCESS != dwError)
            {
                RETAILMSG(1, (L"[OAL] NKRegCreateKeyEx \"%s\" failed, error %d\r\n", pszKeyPath, dwError));
                break;
            }
    
            if (REG_CREATED_NEW_KEY == dwDisp)
            {
                RETAILMSG(1, (L"[OAL] Created new key \"%s\", won't query value because it won't exist!\r\n", pszKeyPath));
                break;
            }
    
            dwSize = sizeof(DWORD);
            dwType = REG_DWORD;
    
            dwError = NKRegQueryValueEx(hKey, pszKeyName, NULL, &dwType, (LPBYTE)pdwValue, &dwSize);
            if (ERROR_SUCCESS != dwError)
            {
                RETAILMSG(1, (L"[OAL] NKRegQueryValueEx \"%s\" failed, error %d\r\n", dwError, pszKeyName));
                break;
            }
    
            bRet = TRUE;
            // Always break out of loop
            break;
        }
    
        // Clean up
        if (hKey)
            NKRegCloseKey(hKey);
    
        return bRet;
    }


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.


    Thursday, August 21, 2014 8:05 AM
    Moderator