Chapter
5
—
Printer Support
Opening the NPCP Driver
Closing the NPCP Driver
Reading from the NPCP Driver
Writing to the NPCP Driver
NPCP Driver I/O Controls
164
The application opens the NPCP driver by using the CreateFile()
function. The call can be implemented as follows. The first parameter
"LPT9:" must reflect the device name and index used in the
RegisterDevice() function call and will fail for any of the following reasons:
hFile = CreateFile(_T("LPT9:"), GENERIC_WRITE |
GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,
NULL);
S The port associated with the device during RegisterDevice() is in use.
S The NPCP device is already open.
S The share mode is not set to zero. The device cannot be shared.
S Access permissions are not set to GENERIC_WRITE |
GENERIC_READ. Both modes must be specified.
Using the CloseHandle() (hFile) function closes the NPCP driver. Where
hFile is the handle returned by the CreateFile() function call.
S TRUE = the device is successfully closed.
S FALSE = an attempt to close NULL HANDLE or already closed device.
Reading of the NPCP printers is not supported since all responses from
the printer are the result of commands sent to the printer.
DeviceIoControl() functions are provided where data is to be received
from the printer.
All Print data can be sent to the printer using the WriteFile() function.
The print data written to the driver must contain the proper printer
commands for formatting. If the function returns FALSE, the NPCP error
may be retrieved using IOCTL_NPCP_ERROR. See the description on
the next page.
An application uses the DeviceIoControl() function to specify an printer
operation to be performed. Certain I/O controls are required to bind and
close communication sessions with the printer, and must be completed
before any other commands to the driver can execute properly.
The function returns TRUE to indicate the device successfully completed
its specified I/O control operation, otherwise it returns FALSE. The
following I/O control codes are defined:
700 Series Color Mobile Computer User's Manual