Initializing the Pen Driver

After installing the virtual pen driver, Windows next reads the pen installable driver component from the installable driver line of the SYSTEM.INI file. It loads the specified pen driver by calling the OpenDriver function, using the PENC.DRV filename. When the driver successfully loads, Windows sends it three messages in the following order: DRV_LOAD, DRV_ENABLE, and DRV_OPEN. The PENC.DRV driver handles these messages in its DriverProc function.

Handling the DRV_LOAD Message

The pen driver responds to DRV_LOAD by calling the multiplex interrupt (interrupt 2Fh) to get the protect-mode entry point in the previously-loaded virtual pen driver. The following code illustrates this:


_asm {
         xor    di, di                          ; Initialize DI to zero.
         mov    ax, GET_VPEND_API_ENTRY_POINT   ; 1684h
         mov    bx, VPenD_Device_ID             ; Virtual Pen Driver ID
         int    2Fh                             ; Multiplex interrupt
; On return, ES:DI points to protect mode entry point in VxD.
         mov    word ptr vlpfnVpenD_API_Entry_Point+2, es;
         mov    word ptr vlpfnVpenD_API_Entry_Point, di
}

If the virtual pen driver does not respond, the pen driver will return a failure condition to Windows. However, if the virtual pen driver exists in memory and responds correctly to the call, the pen driver next fills in a VPEND_INIT structure with information for the virtual pen driver to use. The pen driver then calls the virtual pen driver entry point that is pointed to by ES:DI. The virtual pen driver records the information for future use and initializes the DRV_PENINFO structure pointed to by the lpPenInfo member of the VPEND_INIT structure. All the members of the VPEND_INIT and DRV_PENINFO structures are defined in the "Reference" section of About the Pen Driver.

Handling the DRV_ENABLE Message

When the pen driver receives the DRV_ENABLE message from Windows, it calls the virtual pen driver to begin reflecting interrupts into the system. The virtual pen driver then sets a callback timer for handling out-of-range packets and returns. For a definition of out-of-range packets and a description of how they are handled see the section "Time-Based Interrupts" in About the Virtual Pen Driver.

Handling the DRV_OPEN Message

When the pen driver receives the DRV_OPEN message, it returns the value DRV_SUCCESS unless

Registering the PENWIN.DLL Callback Function

When the PENWIN.DLL library loads, it opens the pen driver. PENWIN.DLL sends the pen driver a DRV_SetEntryPoints message, specifying a ProcessTabletEvents entry point in PENWIN.DLL. For a description of the ProcessTabletEvents function, see the "Reference" section in About the Pen Driver. This is the entry point the driver calls at interrupt time to provide pen packet information to its client, the PENWIN.DLL library.