Most printer drivers include special functions that an application can use to control print settings for that driver and printer port.
Windows printer drivers (for versions 3.0 and later) include the ExtDeviceMode function, which provides many ways for an application to alter print settings without affecting other applications. An application can also use this function to return a copy of the settings in a driver's DEVMODE structure; the application can then modify those settings, rather than creating a DEVMODE structure from scratch. (ExtDeviceMode also includes the functionality that the DeviceMode function provides in older drivers.)
Windows drivers also include the DeviceCapabilities function. The application can use this function to determine which DEVMODE members a particular driver supports.
Older printer drivers include the DeviceMode function. This function displays a dialog box from which the user can select print settings, such as page orientation and paper size, for the printer. The user's changes affect the WIN.INI file and the printer environment.
Because device-driver functions are part of the device driver and are not regular Windows functions, you must use the following procedure to call a device-driver function:
1.Load the device driver into memory by calling the LoadLibrary function.
2.Use the GetProcAddress function to retrieve the address of the function you want. (If GetProcAddress returns a NULL pointer, then that device driver does not provide the function you requested.)
3.Use the pointer returned by GetProcAddress to call the device-driver function.
4.After you have finished using the device-driver function, call the Windows FreeLibrary function to unload the device driver from the system.
The following example calls the ExtDeviceMode function of the PSCRIPT.DRV printer driver:
FARPROC lpfnExtDeviceMode;
FARPROC lpfnDeviceMode;
HINSTANCE hDriver;
if ((hDriver = LoadLibrary("PSCRIPT.DRV")) =< 32) {
.
. /* Handle the error. */
.
}
lpfnExtDeviceMode = GetProcAddress(hDriver, "ExtDeviceMode");
if (lpfnExtDeviceMode != NULL) {
/*
* If the driver supports ExtDeviceMode, call the driver's
* ExtDeviceMode function, using the procedure address in
* lpfnExtDeviceMode.
*/
}
else {
/*
* The driver is not a Windows 3.x driver and does not support
* the newer functions; use the DeviceMode function instead.
*/
lpfnDeviceMode = GetProcAddress(hDriver, "DeviceMode");
if (lpfnDeviceMode != NULL) {
/*
* If the driver supports DeviceMode, call the driver's
* DeviceMode function by using the procedure address in
* lpfnDeviceMode.
*/
}
}
FreeLibrary(hDriver); /* when finished, unloads driver from memory */