O'Reilly logo

Professional Windows® Embedded Compact 7 by Thierry Joubert, David Jones, Samuel Phung

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

image
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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required