DRIVER CONTEXT

A Stream Driver has two types of contexts. One is for the driver, and the other is for any streams opened with it.

Device Context

As mentioned previously, the driver context is established in XXX_Init, and there is only one driver context for each loaded driver. This context is represented by a structure that stores information about the driver that it gets from its registry entries. The structure is specific to the driver. The number of instances of the driver are stored in the device context, so XXX_Init can limit the number of such instances. The number of opened streams to the driver can also be a device context and can be used to limit the number of such streams that are open. If multiple streams are permitted, the device driver needs to employ multitasking mechanisms to function currently. A typical code for XXX_Init is shown here.

image
 PDEVCONTEXT pDevContext; HKEY hKey; //Get registry information hKey = RegDeviceOpen((LPCWSTR)pContext); . . . . . . . . RegCloseKey(hKey); //Check whether driver has been loaded, and check its index . . . . . . . . //Create an instance of the device context on the heap pDevContext = (PDEVCONTEXT)LocalAlloc(LPTR,sizeof(DEVCONTEXT)); if (pDevContext == NULL){ return NULL; } // Initialize the device context pDevContext->hMsgQ=NULL; pDevContext->dwSize = sizeof(DEVCONTEXT); . . . . . . . . pDevContext->OpenCount = 0; InitializeCriticalSection(&pDevContext->CS); ...

Get Professional Windows® Embedded Compact 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.