Devmode Structure Printer Driver

-->

Jan 21, 2001 The DEVMODE structure stores information about various settings and properties of a device, such as a printer. Some of the properties only apply to certain devices; for example, the dmDisplayFrequency has no relevant meaning for a printer. To determine which data members of the structure contain useful information, check the flags set in dwFields. Mar 20, 2020 Hi, Thanks for posting here. It is documented in OpenPrinter. The DEVMODE settings defined in the PRINTERDEFAULTS structure of the pDefault parameter are not used when the value of the pDatatype member of the DOCINFO1 structure that was passed in the pDocInfo parameter of the StartDocPrinter call is 'RAW'.

Devmode structure printer driver free

The DEVMODEW structure is the Unicode version of the DEVMODE structure, which is described in the Microsoft Windows SDK documentation. (The 'W' suffix on DEVMODEW stands for 'wide', or Unicode characters.) While applications can use either structure, drivers are required to use the DEVMODEW structure rather than the DEVMODE structure.

Public and Private Members

Immediately following a DEVMODEW structure's defined members (often referred to as its public DEVMODEW members), there can be a set of driver-defined members (its private DEVMODEW members). The following figure shows the public section (the actual DEVMODEW structure itself) and the private section.

The extra stuff after the standard DEVMODE structure is dependent on the printer driver. It should start with a OEMDMEXTRAHEADER structure followed by the driver specific fields. These are used for the fancy extras that make programming printers so much fun such as collation, stapling, special paper handling, custom colour modes etc. Devmode.pdf The DEVMODE structure The DEVMODE structure is a Windows API structure that contains information about a printer driver's initialization and environment data. An application passes this structure to the DeviceCapabilities and ExtDeviceMode functions. The DEVMODE structure is also used by the Seagate Crystal Reports. Specifies the version number of the initialization data specification on which the structure is based. Specifies the printer driver version number assigned by the printer driver developer. Specifies the size, in bytes, of the DEVMODE structure except the dmDriverData (device-specific) member. If an application.

Normally, the private members are used only by printer drivers. The driver supplies the size, in bytes, of this private area in the dmDriverExtra member. Driver-defined private members are for exclusive use by the driver.

For printer drivers, the DEVMODEW structure is used to specify user choices for a print document. It is also used to specify default values of these choices for printers, such as the number of copies to print, paper size, and other attributes. For display devices, the DEVMODEW structure specifies display attributes such as the number of bits per pixel, pixel dimensions, and display frequency.

Initializing a DEVMODEW Structure

Structure

Depending on whether it is to be used by a display driver or by a printer driver, a DEVMODEW structure is initialized in two different ways.

  • Display driver DEVMODEW initialization

    A display driver's DrvGetModes entry point initializes all members of the DEVMODEW structure to zero. DrvGetModes then copies the name of the display driver DLL to the dmDeviceName member, fills in the dmSpecVersion and dmDriverVersion members with the version of the DEVMODEW structure, and copies display attribute information to the appropriate members.

  • Printer driver DEVMODEW initialization

    When an application makes a call to either DocumentProperties (a printer interface DLL function that is described in the Microsoft Windows SDK documentation) or DrvDocumentPropertySheets (an NT-based operating system graphics DDI), a DEVMODEW structure is created with default values. An application is then free to modify any of the public DEVMODEW members. After any changes, the application should then make a second call to the same function it called before, in order to merge the changed members with those of the driver's internal DEVMODEW structure. The second call is necessary since some changes may not work correctly; the printer driver must be called to correct the DEVMODEW structure. When the document is about to be printed, the application passes the merged DEVMODEW structure to CreateDC (described in the Microsoft Windows SDK documentation), which passes it on to the DrvEnablePDEV DDI. At that time, the driver's rendering DLL validates the DEVMODEW structure and makes repairs, if necessary, before carrying out the print job.

Using a DEVMODEW Structure

Several APIs and graphics DDIs use the information in the DEVMODEW structure for such purposes as printing, querying device capabilities, showing user interface, and others. For example, DrvConvertDevMode is a print spooler graphics DDI that translates the DEVMODEW structure from one operating system version to another. This might be necessary if a printer driver gets a DEVMODEW structure from another machine that is running on a different operating system version.

Modifying a DEVMODEW Structure

Devmode structure printer driver downloads

Applications and drivers are free to ask for a DEVMODEW structure and modify its public part directly. Only drivers, however, are permitted to modify the private DEVMODEW structure members.

Devmode Structure Printer Driver Windows 10

In order to modify private DEVMODEW structure members, a driver must first determine the offset of the beginning of the private data. Given a pointer to the beginning of this structure, and the dmSize member, which holds the size of the public portion of the structure, the beginning of the private portion can be found. The following example shows how to initialize a pointer to the beginning of the private section. In this example, pdm points to the beginning of the DEVMODEW structure.

Printer Driver/Display Driver DEVMODEW Differences

The DEVMODEW structure members fall into three categories:

  • Members used only by printer drivers

  • Members used only by display drivers

  • Members used by both printer and display drivers

The following table lists several public DEVMODEW members that are used only by printer drivers:

Used Only by Printer DriversPurpose
dmScaleSpecifies the percentage by which the image is to be scaled for printing.
dmCopiesSpecifies the number of copies to be printed.
dmColorSpecifies whether a color printer should print color or monochrome.
dmOrientationSpecifies the orientation of the paper, either portrait or landscape.

The next table lists several public DEVMODEW members that are used only by display drivers:

Used Only by Display DriversPurpose
dmBitsPerPelSpecifies the color resolution, in bits per pixel, of the display device.
dmPelsWidthSpecifies the width, in pixels, of the visible device surface.
dmPelsHeightSpecifies the height, in pixels, of the visible device surface.
dmDisplayFlagsSpecifies the display mode - color versus monochrome, interlaced versus noninterlaced.
dmDisplayFrequencySpecifies, in hertz, the display's refresh rate.
DevmodeDownload

The third table lists several public DEVMODEW members that are used by both printer and display drivers:

Printer Driver Download

Used by Printer and Display DriversPurpose
dmDeviceNameFor displays, specifies the display driver's DLL. For printers, specifies the 'friendly name' of the printer.
dmFieldsSpecifies bit flags identifying which of the DEVMODEW members that follow it are in use. For example, the DM_BITSPERPEL flag is set when the dmBitsPerPel member contains valid data.
dmSizeSpecifies the size, in bytes, of the public portion of the DEVMODEW structure.
dmDriverExtraSpecifies the number of bytes of private driver data following the public structure members. For display drivers, this is usually zero.

Introduction

If you want to get the location ('Printer room, second floor') of a printer device, you won't find it in the DEVMODE or DEVNAMES structure - you must use the Windows printer API. To make it easier to get, I've wrapped the printer API in a class called GPrinter:

In order to use this class, you must first get the name of the printer from the DEVNAMES structure. In the image above, the name would be 'HP LaserJet 5P'. Use that name to call the GPrinter::Open() function. From there, you can use any of the API wrapper functions. Currently, it wraps only one function, ::GetPrinter(), with a series of overloaded Get() functions, each taking a specific type of PRINTER_INFO_*struct. There is some information overlap between the seven different types of structs - I use PRINTER_INFO_2 to get the printer location:

Use the GPrinter::SetSilent() function to turn off the display of error messages. There are more printer API functions which can be added to this class that I never got around to wrapping - feel free to add them. Here is the implementation for this class:

Collapse