Initializing and Configuring a Driver, Using VCKernel.lib

Initialization and configuration operations take place in a kernel-mode driver’s DriverEntry function. Video capture drivers using VCKernel.lib, such as bravado.sys, must call VC_Init from within DriverEntry, before calling any other VCKernel.lib function. The VC_Init function creates a device object named “vidcapx”, where x is incremented from 0 for each new video capture device object, and creates an entry for the device in the registry.

After calling VC_Init, bravado.sys calls VC_ReadProfile to obtain hardware configuration parameters that were stored by the user-mode driver. These parameters are used as input to VC_GetResources, which reserves system resources for the device, and maps the device’s I/O address space and frame buffer into system address space.

Kernel-mode drivers using VCKernel.lib must provide a set of driver functions used with VCKernel.lib, so bravado.sys next calls VC_GetCallbackTable to get the address of VCKernel.lib’s callback table, and fills in the table with the addresses of driver-supplied functions.

After the callback table has been filled, device hardware can be initialized. The bravado.sys driver places initial values in device registers and then calls VC_ConnectInterrupt to connect the driver’s interrupt service routine with the device’s interrupt number. Then it confirms that interrupts can be received.

If bravado.sys detects an error during execution of its DriverEntry function, it calls VC_WriteProfile to write an error code into the registry. The user-mode driver can read the registry entry to determine if the kernel-mode driver initialized properly.

Before a kernel-mode driver is unloaded, VCKernel.lib calls VC_Cleanup, which in turn calls the driver-supplied CleanupFunc function. The VC_Cleanup function releases resources allocated by VC_Init and VC_GetResources. The driver’s CleanupFunc function might disable hardware and free any driver memory allocations. Besides being called by VCKernel.lib before the driver is unloaded, VC_Cleanup is typically called by the driver itself if the driver detects an error within DriverEntry any time after calling VC_Init.