Windows CE : Accessing Registry From your Driver

If you know a particular a registry key name then reading the value of the key can be done by using RegQueryValueEx function. Passing NULL as the fifth argument will return the length then you can allocate a bu er of that length and pass the pointer of it.

Suppose I have added a key value pair in platform.reg as shown below:

"Dll"="StreamTestDrv.dll"
"Order"=dword:1
"Index"=dword:1
"Prefix"="DRV"
"Flags"=dword:0010 ; User Mode: 0010 means DEVFLAGS_LOAD_AS_USERPROC
"DisplayName"="User Mode Driver"


In order to access the value of the key "DisplayName", Modify the DRV_Init function which was written in the previous post

DWORD DRV_Init(LPCTSTR pContext, LPCVOID lpcContext)
{
    HKEY hkey;
    ULONG ktype;
    char kvalue[100];
    DWORD klength = sizeof(kvalue);
    RETAILMSG(TRUE, (TEXT("DRV Driver:DD_Init:%s\n"), pContext));
    hkey = OpenDeviceKey(pContext);
    if (hkey == INVALID_HANDLE_VALUE)
   {
        RETAILMSG(TRUE, (TEXT("iNVALID Handle value\n")));
   }
   else
   {
        //first find out the length
        RETAILMSG(TRUE, (TEXT("Regqueryvalueex returns:%d\n"),RegQueryValueEx(hkey,                                           L"DisplayName", NULL,&ktype, NULL, &klength)));
        RETAILMSG(TRUE, (TEXT("KLENGTH:%d\n"), klength));
       if (klength > 0)
       {if (RegQueryValueEx(hkey, L"DisplayName", NULL, &ktype,
           (LPBYTE)&kvalue, &klength) == ERROR_SUCCESS)
       {
                RETAILMSG(TRUE, (TEXT("DisplayName: %s\n"), kvalue));
       }
       else
      {
                RETAILMSG(TRUE, (TEXT("Reg Query Failed:%d\n"),
                                          GetLastError()));
       }
       }
    }
    //This function releases the handle of the specified key.
    RegCloseKey(hkey);
    return 0x01;
}

Comments

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto