Delphi - DeviceCapabilities Declaration Problem

The Windows API function is used to get information from a printer device driver. Unfortunately, the related Delphi prototype has a minor problem. I have verified this issue with Delphi versions 5 & 6.

Background | Windows SDK | windows.pas | winspool.pas | Solution | Paper Names Example


Background

Delphi uses TPrinters to provide a wrapper for many of the print related Windows API methods ... but not for all of them.

For instance, there is a major problem printing images.

In addition, the Windows API function DeviceCapabilities must be used to get some of the printer capabilities. In most applications, this information is not required. However, I had a situation where I wanted to simplify the configuration of a barcode printer - this page documents one of the problems I had.


Windows SDK

This definition is from the Windows SDK distributed with Delphi.


windows.pas

The following is from windows.pas - notice that it does not match the Windows SDK - it has a different number of parameters and calls the wrong dll file. I noticed the different number of arguments right off (the program would not compile), but still had trouble with the program crashing with an access violation. I searched google for The second reference was how to call the Windows API function DeviceCapabilities by Joe C. Hecht. This indicated that the correct library was I verified the library by using depends.exe (the Microsoft Dependency Walker).


winspool.pas

These are the correct declarations from winspool.pas.


Solution

Include winspool AFTER windows in your uses clause.


Paper Names Example

This example is based on a VisualBasic Macro to Obtain a List of Paper Names Supported by the Active Printer. It displays the available paper types, by name, for the current printer.

First, include winspool and Printers to your uses clause.


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / Delphi / DeviceCapabilities.html