GDI enables the display driver by calling the Enable function and directing the driver to initialize a physical device for subsequent graphics output. A physical device is a PDEVICE structure that represents the display and its current operating state. A display driver uses the physical device information to determine how to carry out specific tasks, such as which display mode to use. The display driver initializes the physical device by copying information to the PDEVICE structure.
During initialization, GDI calls Enable twice: once to retrieve a copy of the driver's GDIINFO structure, and another time to initialize the PDEVICE structure. GDI allocates memory for the PDEVICE structure and calls Enable, passing a pointer to the structure. At this point, the driver initializes the display hardware and the structure.
Although only the display driver initializes and uses the PDEVICE structure, it is GDI that allocates memory for the structure, determines when to pass it to the driver's output functions, and deletes the structure when it is no longer needed.
Each minidriver has to create a PDEVICE structure in a format recognized by the DIB Engine. If the surface being drawn to is video memory, a device-independent bitmap (DIB), or a color device-dependent bitmap (DDB), the PDEVICE is in the format of a DIBENGINE structure. If the surface is a monochrome bitmap, the PDEVICE is in the format of a PBITMAP structure. The deType member of the PDEVICE identifies the format of the structure; it must be either TYPE_DIBENG (0x5250) if in the DIBENGINE format or 0 if in the PBITMAP format.
In some cases, for example, when a full-screen .AVI file is played, GDI calls Enable once to have the driver reinitialize the display hardware, the PDEVICE structure, and any screen data that may have been discarded. Additionally, Enable is called when a dynamic resolution change occurs.
Note that it is possible that a Windows® 3.1 application may call the driver directly passing it a Windows 3.1 style PBITMAP structure. If the deType member is zero, but the deBitsPixel member is not equal to one, then the structure is a Windows 3.1 style PBITMAP structure. In this case, if the driver is using the DIB engine, it should pass the structure to the DIB engine and let the DIB engine handle the call.
GDI calls the Disable function in a variety of cases, such as when a full-screen .AVI file is played, or when Windows quits. GDI disables the display driver by calling the Disable function. If the driver has allocated any memory or selectors, it must free them in the Disable function. After the driver returns from the Disable function, GDI frees the memory it allocated for the PDEVICE structure and frees the driver, removing any driver code and data from memory.