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

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); ...

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