September 2011
Intermediate to advanced
744 pages
19h 4m
English
REGISTRY ACCESS FROM A DRIVER
When XXX_Init runs, the pContext parameter that is passed to it is a LPCTSTR string data type which names the HKLM\Drivers\Active string, and the driver instance that it is loaded under, relative to HKLM. It can be used to access registry information about the driver, from within the driver. Here is a function that gets the instance name as the original key entry for the driver (lpKeyName) and the driver’s active name (lpActiveKeyName). The active name is the string that an application would use to open the stream, such as MYD1:. The function also extracts the index from this.
DWORD index=0; WCHAR ActiveKeyName[8] ; LPWSTR lpActiveKeyName; TCHAR KeyName[256] = {0}; LPWSTR lpKeyName; Void RegDeviceOpen(LPCWSTR lpActiveKey ) { HKEY hKey; DWORD ValueType,ValueSize; DWORD Disposition; //Open the driver instance active registry entry RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpActiveKey, 0, NULL, 0, 0, NULL, &hKey, &Disposition); ValueSize = sizeof(szKeyName) * sizeof(TCHAR); RegQueryValueEx(hKey, _T("Key"), 0, &ValueType, (LPBYTE)KeyName, &ValueSize); //Store the driver key lpKeyName = (LPWSTR) lpKeyName; ValueSize = 8*sizeof(WCHAR); RegQueryValueEx(hKey, _T("NAME"), NULL, &ValueType, //REG_SZ (LPBYTE) &ActiveKeyName, &ValueSize); RegCloseKey(hKey); //Get index index = (BYTE)ActiveKeyName[3] - (BYTE) '0'; //Store the active name string, eg MYD1: lpActiveKeyName ...Read now
Unlock full access