Printer Copy
![]() |
![]() BNIB hp deskjet 1051 energy saver printerscan copy All In One Office Machine US $49.95
|
Port Monitor: How to receive the number of document copies during the printing
Contents:
- Introduction
- Problem Review
- DEVMODE and Spool File
- Getting Copies Count
- Demo project class architecture
1. Introduction
In this article, we will examine a problem of receiving the correct value of the dmCopies variable in the DEVMODE structure while printing from Microsoft Word 2003. This can be useful for the case of writing a program that controls printing (to printers, as well as to files).
2. Problem Review
During the printing, you can define the number of copies to print. You can receive the defined number of copies with the help of the GetJob function in the program (for more information see - http://msdn.microsoft.com/en-us/library/dd144894(VS.85).aspx). But the number of these copies will be invalid while printing from Microsoft Word 2003 and will be always equal to 1.
We will receive the JOB_INFO_2 structure (or the JOB_INFO_1 structure depending on the type, which was defined in the Level field). This structure, in its turn, contains the DEVMODE structure. The last one contains the important for us dmCopies value.
3. DEVMODE and Spool File
So, what is the process of receiving the DEVMODE.dmCopies value? We can receive the DEVMODE structure by intercepting the StartDocPort function. As it was mentioned before, we get the invalid number of copies while printing from MSWord. In this case, the correct dmCopies value is stored in the Spool File, which, in its turn, is created during the printing. This file contains the copy of the DEVMODE structure. We can get the last in a different way (with the help of the GetJob function), but with the correct value of the dmCopies field. You should take into account that this copy of the structure is not created in the Spool File during the printing from the majority of programs, and also this file has another structure. To get the full description of the Spool File structure, see http://msdn.microsoft.com/en-us/library/cc231034(PROT.13).aspx
The common universal algorithm of receiving the correct value of the number of copies includes the following steps:
- Receive the pointer to the Spool File;
- Check if the Spool File has the necessary format (it must have the EMFSPOOL format). Read the file header where the version (EMFSPOOL_VERSION) is stored. If the format of the header or the version do not correspond – move to the step 5, otherwise to the step 3;
- Spool File consists of separate records with the indication of size and type of the record. All records go one by one serially. By reading each record by turn we find the record of the DEVMODE structure. If the structure is not found, move to the step 5, otherwise to the step 4;
- Read the DEVMODE structure. You receive the correct value of the number of copies;
- Receive the number of copies with the help of the GetJob function (see the reference above).
Now let's examine it in detail with the code examples.
Step 1. Receive the pointer to the SpoolFile with the help of the OpenPrinter function:
HANDLE hSpoolFile = INVALID_HANDLE_VALUE;
std::wstringstream sPrinterName;
sPrinterName << pPrinterName;
sPrinterName << _T(",Job ");
sPrinterName << JobId;
OpenPrinter((LPWSTR)sPrinterName.str().c_str(), &hSpoolFile, NULL);
Step 2. Check the Spool File for the data correctness.
The following example shows how to perform the data reading from the Spool File:
[Code from .PrinterEmfSpoolReader.cpp]
BOOL ReadSpoolFile( HANDLE hSpoolFile, LPVOID pBuf, DWORD cbBuf )
{
DWORD dwRead = 0;
LPBYTE pTempBuf = (LPBYTE)pBuf;
while ( ::ReadPrinter(hSpoolFile, pTempBuf, cbBuf, &dwRead) && (dwRead > 0) )
{
pTempBuf += dwRead;
cbBuf -= dwRead;
if (cbBuf == 0)
{
return TRUE;
}
}
return FALSE;
}
So, we read the header of the Spool File and compare the version:
[Code from .PrinterEmfSpoolReader.cpp]
#define EMFSPOOL_VERSION 0x00010000
//more information about EMRI_HEADER see in MS-EMFSPOOL specification
typedef struct tagEMRIHEADER {
DWORD dwVersion;
DWORD cjSize;
DWORD dpszDocName;
DWORD dpszOutput;
} EMRI_HEADER, *PEMRI_HEADER;
BOOL OpenSpoolFile( HANDLE hSpoolFile )
{
EMRI_HEADER splHeader = {0};
BOOL bIsEmfData = ReadSpoolFile( hSpoolFile, &splHeader, sizeof(splHeader) ) && ( EMFSPOOL_VERSION == splHeader.dwVersion );
if ( !bIsEmfData )
{
return FALSE;
}
DWORD nSize = splHeader.cjSize - sizeof(splHeader);
if ( 0 != nSize )
{
std::vector<BYTE> buffer(nSize);
ReadSpoolFile(hSpoolFile, &buffer.at(0), nSize);
}
return TRUE;
}
Steps 3 and 4. Look through the records of the Spool File, find the DEVMODE record, and read it:
[Code from .PrinterEmfSpoolReader.cpp]
#define EMRI_DEVMODE 0x00000003
BOOL GetDevModeStruct( std::vector<BYTE> &buffer )
{
if ( hSpoolFile == INVALID_HANDLE_VALUE )
{
return FALSE;
}
if ( NULL == hSpoolFile )
{
return FALSE;
}
for (;;)
{
EMRI_RECORD_HEADER emriRecordHeader = {0};
if ( !ReadSpoolFile(&emriRecordHeader, sizeof(emriRecordHeader)) )
{
break;
}
if ( IsCorrectEmriHeader(emriRecordHeader) )
{
buffer.resize(emriRecordHeader.cjSize);
if ( !ReadSpoolFile(&buffer.at(0), emriRecordHeader.cjSize) )
{
break;
}
if ( EMRI_DEVMODE == emriRecordHeader.ulID )
{
return TRUE;
}
}
else
{
break;
}
}
buffer.clear();
return FALSE;
}
Step 5. If you did not receive the DEVMODE structure or the Spool File had another format during the previous steps, you can receive the structure with the help of the GetJob function (see the reference above):
[Code from .PrinterPrinter.cpp]
HANDLE hPrinter = 0;
HANDLE hSpoolFile = 0;
std::vector<BYTE> buffer;
PDEVMODE pDevModeFromSpool = NULL;
DEVMODE devMode = {0};
DWORD error = 0;
EmfSpoolReader reader(pPrinterName, JobId);
if ( reader.GetDevModeStruct(buffer) )
{
pDevModeFromSpool = reinterpret_cast<PDEVMODE>(&buffer.at(0));
}
else if ( ::OpenPrinter(pPrinterName, &hPrinter, NULL) )
{
GetDevMode(hPrinter, JobId, &devMode);
::ClosePrinter(hPrinter);
}
Finally, if the pDevModeFromSpool pointer is equal to 0, the correct value of the number of copies is stored in the devMode, otherwise in the pDevModeFromSpool.
5. Demo project
The demo project is performed in the form of the Port Monitor implementation and is the superstructure of the Local Port system monitor.
Demo project includes 2 projects:
Port Monitor Installer, executable:
.InstallPortMon
InstallPortMon.cpp
Stdafx.cpp
Stdafx.h
Port Monitor, dynamic library:
.Printer
emfspool.h
EmfSpoolReader.cpp
EmfSpoolReader.h
Printer.cpp
Printer.h
stdafx.cpp
stdafx.h
winsplp.h
All functions are called from the Local Port. An example of getting the number of copies is implemented in the StartDocPort function.
To view the result, do the following:
- Install the Port Monitor;
- Add any printer to the Sample Port Monitor;
- Send any document to the printer;
- The number of copies will be displayed in the MessageBox.
Download example (18 KB).
About the Author
Apriorit is provider of professional consulting and software development services for IT companies worldwide.
|
|
Page Printer $70.1 High Quality Content by WIKIPEDIA articles A page printer is a type of computer printer that prints on cut sheet paper. A modern page printer may use any of various technologies, such as laser, LED or inkjet. Most modern computer printers are page printers.The page printer was jointly developed (circa 1900) and patented in 1924 by Sterling Morton and Howard Krum..In computing, a printer is a peripheral which produces a hard copy (permanent readable text and/or graphics) of documents stored in electronic form, usually on physical print media such as paper or transparencies. Author: Surhone, Lambert M./ Timpledon, Miriam T./ Marseken, Susan F. Binding Type: Paperback Number of Pages: 92 Publication Date: 2010/07/19 Language: English Dimensions: 6.00 x 9.02 x 0.22 inches |
|
|
4497B001 - Imageclass Mf9280Cdn Multifunction Laser Printer, Copy/Fax/Print/Scan $1859.06 developed to Address The Needs of Today's Fast-paced End-user, The New Color Imageclass Mf9280cdn Laser Multifunction Printer Allows Small Businesses And Work Groups to Maximize Productivity With Convenient Print, Copy, Fax And Scan Functionality in a Fully Networkable Device. [CNM4497B001] UPC: 013803126112 UNSPC: 43212105 30.32L x 27.76W x 25.39H 125 LB 12.36 Cubes |
|
|
This Is A Copy Is This A Copy $12.49 This Is A Copy Is This A Copy |
|
|
Canon Copier, Printer, Scanner - 23ppm Mono Print - 1200 x 600dpi Print - 23cpm Mono Copy - 600dpi Optical Scan - 251 sheets In $233.43 Canon Copier, Printer, Scanner - 23ppm Mono Print - 1200 x 600dpi Print - 23cpm Mono Copy - 600dpi Optical Scan - 251 sheets In |
|
|
OKI Electric Printer, Fax, Scanner, Copier - 55ppm Mono Print - 1200 x 1200dpi Print - 55cpm Mono Copy - 600dpi Optical Scan - $4200 OKI Electric Printer, Fax, Scanner, Copier - 55ppm Mono Print - 1200 x 1200dpi Print - 55cpm Mono Copy - 600dpi Optical Scan - |
|
|
Canon Printer, Copier, Scanner, Fax - 22ppm Mono/22ppm Color Print - 2400 x 600dpi Print - 22cpm Mono/22cpm Color Copy - 600dpi $1518.94 Canon Printer, Copier, Scanner, Fax - 22ppm Mono/22ppm Color Print - 2400 x 600dpi Print - 22cpm Mono/22cpm Color Copy - 600dpi |
|
|
Lexmark Printer, Copier, Scanner, Fax - 40ppm Mono Print - 1200 x 1200dpi Print - 40cpm Mono Copy - 600dpi Optical Scan - 300 s $1944.68 Lexmark Printer, Copier, Scanner, Fax - 40ppm Mono Print - 1200 x 1200dpi Print - 40cpm Mono Copy - 600dpi Optical Scan - 300 s |
|
|
Canon Printer, Copier, Scanner - 22ppm Mono/22ppm Color Print - 2400 x 600dpi Print - 22cpm Mono/22cpm Color Copy - 600dpi Opti $1548.69 Canon Printer, Copier, Scanner - 22ppm Mono/22ppm Color Print - 2400 x 600dpi Print - 22cpm Mono/22cpm Color Copy - 600dpi Opti |
|
|
OKI Electric Copier, Scanner, Fax, Printer - 25ppm Mono/23ppm Color Print - 1200 x 600dpi Print - 25cpm Mono/23cpm Color Copy - $575.97 OKI Electric Copier, Scanner, Fax, Printer - 25ppm Mono/23ppm Color Print - 1200 x 600dpi Print - 25cpm Mono/23cpm Color Copy - |
|
|
OKI Electric Copier, Scanner, Fax, Printer - 31ppm Mono/27ppm Color Print - 1200 x 600dpi Print - 31cpm Mono/27cpm Color Copy - $768.59 OKI Electric Copier, Scanner, Fax, Printer - 31ppm Mono/27ppm Color Print - 1200 x 600dpi Print - 31cpm Mono/27cpm Color Copy - |
|
|
OKI Electric Printer, Copier, Scanner, Fax - 30ppm Mono Print - 1200 x 1200dpi Print - 22cpm Mono Copy - 300 sheets Input - Fas $649.68 OKI Electric Printer, Copier, Scanner, Fax - 30ppm Mono Print - 1200 x 1200dpi Print - 22cpm Mono Copy - 300 sheets Input - Fas |
|
|
Lexmark Printer, Copier, Scanner - 33ppm Mono/30ppm Color Print - 4800 x 1200dpi Print - 25cpm Mono/21cpm Color Copy - 100 shee $315.89 Lexmark Printer, Copier, Scanner - 33ppm Mono/30ppm Color Print - 4800 x 1200dpi Print - 25cpm Mono/21cpm Color Copy - 100 shee |
|
|
Samsung Scanner, Copier, Fax, Printer - 17ppm Mono/4ppm Color Print - 2400 x 600dpi Print - 17cpm Mono/4cpm Color Copy - 1200dp $395.53 Samsung Scanner, Copier, Fax, Printer - 17ppm Mono/4ppm Color Print - 2400 x 600dpi Print - 17cpm Mono/4cpm Color Copy - 1200dp |
|
|
Xerox Copier, Scanner, Printer - 55ppm Mono Print - 1200 x 1200dpi Print - 55cpm Mono Copy - 600dpi Optical Scan - 600 sheets I $2953.22 Xerox Copier, Scanner, Printer - 55ppm Mono Print - 1200 x 1200dpi Print - 55cpm Mono Copy - 600dpi Optical Scan - 600 sheets I |
|
|
Samsung Printer, Scanner, Copier, Fax - 37ppm Mono Print - 1200 x 1200dpi Print - 37cpm Mono Copy - 1200dpi Optical Scan - 300 $646.78 Samsung Printer, Scanner, Copier, Fax - 37ppm Mono Print - 1200 x 1200dpi Print - 37cpm Mono Copy - 1200dpi Optical Scan - 300 |
|
|
Canon Printer, Scanner, Copier, Fax - 24ppm Mono Print - 1200 x 600dpi Print - 24cpm Mono Copy - 600dpi Optical Scan - 251 shee $224.2 Canon Printer, Scanner, Copier, Fax - 24ppm Mono Print - 1200 x 600dpi Print - 24cpm Mono Copy - 600dpi Optical Scan - 251 shee |
|
|
Canon Printer, Scanner, Copier - 26ppm Mono Print - 1200 x 600dpi Print - 26cpm Mono Copy - 600dpi Optical Scan - 251 sheets In $327.73 Canon Printer, Scanner, Copier - 26ppm Mono Print - 1200 x 600dpi Print - 26cpm Mono Copy - 600dpi Optical Scan - 251 sheets In |
|
|
Samsung Printer, Scanner, Copier, Fax - 23ppm Mono Print - 1200 x 1200dpi Print - 23cpm Mono Copy - 250 sheets Input - Fast Eth $291.64 Samsung Printer, Scanner, Copier, Fax - 23ppm Mono Print - 1200 x 1200dpi Print - 23cpm Mono Copy - 250 sheets Input - Fast Eth |
|
|
OKI Electric Copier, Scanner, Fax, Printer - 55ppm Mono Print - 1200 x 1200dpi Print - 55cpm Mono Copy - 600dpi Optical Scan - $2630.21 OKI Electric Copier, Scanner, Fax, Printer - 55ppm Mono Print - 1200 x 1200dpi Print - 55cpm Mono Copy - 600dpi Optical Scan - |
|
|
Dell Printer, Copier, Scanner - 40ppm Mono Print - 1200 x 1200dpi Print - 40cpm Mono Copy - 300 sheets Input - Fast Ethernet 33 $947.07 Dell Printer, Copier, Scanner - 40ppm Mono Print - 1200 x 1200dpi Print - 40cpm Mono Copy - 300 sheets Input - Fast Ethernet 33 |
|
|
HP Printer, Copier, Scanner, Fax - 40ppm Mono/40ppm Color Print - 1200 x 600dpi Print - 40cpm Mono/40cpm Color Copy - 600dpi Op $8806.47 HP Printer, Copier, Scanner, Fax - 40ppm Mono/40ppm Color Print - 1200 x 600dpi Print - 40cpm Mono/40cpm Color Copy - 600dpi Op |
|
|
Lexmark Printer, Copier, Scanner, Fax - 43ppm Mono Print - 1200 x 1200dpi Print - 43cpm Mono Copy - 600dpi Optical Scan - 650 s $1950.01 Lexmark Printer, Copier, Scanner, Fax - 43ppm Mono Print - 1200 x 1200dpi Print - 43cpm Mono Copy - 600dpi Optical Scan - 650 s |
|
|
Samsung Printer, Scanner, Copier, Fax - 33ppm Mono Print - 1200 x 1200dpi Print - 33cpm Mono Copy - 1200dpi Optical Scan - 300 $454.6 Samsung Printer, Scanner, Copier, Fax - 33ppm Mono Print - 1200 x 1200dpi Print - 33cpm Mono Copy - 1200dpi Optical Scan - 300 |
|
|
Samsung Printer, Copier, Scanner, Fax - 37ppm Mono Print - 1200dpi Print - 37cpm Mono Copy - 1200dpi Optical Scan - 300 sheets $533.52 Samsung Printer, Copier, Scanner, Fax - 37ppm Mono Print - 1200dpi Print - 37cpm Mono Copy - 1200dpi Optical Scan - 300 sheets |
|
|
Brother Printer, Copier, Scanner, Fax - 27ppm Mono Print - 2400 x 600dpi Print - 27cpm Mono Copy - 600dpi Optical Scan - 250 sh $335.44 Brother Printer, Copier, Scanner, Fax - 27ppm Mono Print - 2400 x 600dpi Print - 27cpm Mono Copy - 600dpi Optical Scan - 250 sh |
|
|
HP Printer, Copier, Scanner, Fax - 19ppm Mono Print - 600 x 600dpi Print - 18cpm Mono Copy - 1200dpi Optical Scan - 150 sheets $257.25 HP Printer, Copier, Scanner, Fax - 19ppm Mono Print - 600 x 600dpi Print - 18cpm Mono Copy - 1200dpi Optical Scan - 150 sheets |
|
|
Samsung Printer, Copier, Scanner, Fax - 55ppm Mono Print - 1200 x 1200dpi Print - 55cpm Mono Copy - 600dpi Optical Scan - 620 s $2841.28 Samsung Printer, Copier, Scanner, Fax - 55ppm Mono Print - 1200 x 1200dpi Print - 55cpm Mono Copy - 600dpi Optical Scan - 620 s |
|
|
Samsung® SCX-4729FD Multifunction Laser Printer, Copy/Fax/Print/Scan. Each $247.57 Manufacturer: Samsung. Each. Increase performance and productivity with this network-ready multifunction laser printer that features fast output speeds and high-quality resolution. Automatic duplex copying and printing allow you to create two-sided docume |
|
|
Cables To Go Parallel Printer Cable $22.99 06097 1 x 25-pin DB-25 Male IEEE 1284 Parallel 1 x 36-pin mini-Centronics Male IEEE 1284 Parallel 20 ft HP 2500C Professional Series Color printer HP Copy Jet Copier HP LaserJet 3100 Printer-Fax-Copier-Scanner Beige Cables To Go Copper DB-25 Data Transfer Cable Lifetime Parallel Printer Cable Printer mini-Centronics www.cablestogo.com |
|
|
Kimberly-Clark Professional® WypAll® MFC-J5910DW Wireless All-in-One Inkjet Printer, Copy/Fax/Print/Scan. Each $241.02 Manufacturer: Brother. Each. Copy, fax, print and scan up to ledger-sized projects with this wireless all-in-one inkjet printer. Free downloadable Brother® iPrint&Scan app works with the MFP and lets you wirelessly print from or scan to your iPhone®, iPad |
|
|
HP® LaserJet Enterprise M4555fskm MFP Laser Printer, Copy/Fax/Print/Scan. Each $6399.21 Manufacturer: HP. Each. Ideal for your enterprise, small or medium business, this network-ready multifunction laser printer delivers a range of tools that increase productivity and reduce costs. High-performance copy and print speeds maximize your uptime. |
|
|
Samsung SF-760P Multifunction Laser Printer, Copy/Fax/Print/Scan. Each $253.02 Manufacturer: Samsung. Each. Achieve more with this multifunction laser printer that features fast printing and high-speed faxing. Four-in-one versatility streamlines workflow, so your office can produce output as efficiently as possible. High resolution |
|
|
Brother DCP-J125 All-in-One Inkjet Printer, Copy/Print/Scan. Each $88.93 Manufacturer: Brother. Each. Quickly create both color and black-and-white output with this sleek and stylish all-in-one inkjet printer that is ideal for home use. Produce vivid, borderless photos, thanks to the high-quality resolution. Insert your camera |
|
|
Lexmark X950de Multifunction Laser Printer, Copy/Fax/Print/Scan. Each $12065.22 Manufacturer: Lexmark. Each. Give your office the power to create professional collateral materials up to 11” x 17” in-house with this network-ready multifunction laser printer. Robust print engine delivers exceptionally fast first-page-out and page-per-m |
|
|
Brother MFC-7440N Multifunction Printer $244.99 1 1 Year Limited 1 x Automatic Document Feeder 35 Sheet 1 x Input Tray 250 Sheet 1 x Output Tray 100 Sheet 10000 pages per month 12" 120 V AC 14.4 15.60" 16.90" 19200 x 19200 dpi 23 24.40 lb 2400 x 600 dpi 25% 250 sheets 32 MB 400% 500 pages 600 dpi 600 x 2400 dpi MFC-7440N Multifunction Printer 1 x Starter Toner Cartridge 1 x Drum (DR360) Laser Multifunction Center MFC-7440N with networking copies, faxes, scans and prints. Print and copy 23 pages per minute with 2400 x 600 dpi. 35-page auto document feeder offers a quick way to copy, fax or scan multipage documents. Other features include a built-in Ethernet network interface, standard USB interface, and 250-sheet paper tray that is adjustable for letter-size or legal-size paper. Copy features include copy scaling from 25 percent to 400 percent and sorting function. Fax function offers a 14.4 Kbps modem, 6 second-per-page transmission, Caller ID/Call Waiting, 208 auto dial locations, 258 broadcasting location, fax forwarding, and automatic redial. Flatbed color scanning has a 19200 x 19200 dpi interpolated resolution and 600 x 2400 dpi optical resolution. 24.4 lb. printer also includes a LCD screen, 32MB memory (500 pages for faxing) and 250-sheet paper tray adjustable for letter-size or legal-size paper. Compatible with Windows and Mac. Energy Star qualified. A4 A5 A6 B5 B6 Brother Brother Industries, Ltd Color Copier Custom Size Desktop Energy Star Ethernet Executive Fax Flatbed Glossy Paper Inkjet Paper Laser Multifunction Printer Legal Letter MFC MFC-7440N MFC-7440N Multifunction Printer Mac Monochrome PC Plain Paper Plain Paper Print Printer Scanner Transparency Yes www.brother-usa.com |
|
|
HP Officejet 4500 Printer $69.99 The HP Officejet 4500 Printer is ideal for home office use. Easy to use reliable and economical you'll be able to print copy scan and fax all from one device. It offers speeds as fast as 28 pages per minute in black and 22 ppm in colour. Plus if you use the HP Officejet inks (sold separately) you'll get professional-quality colour printing at a low cost per page. |
|
|
Panasonic KX-FLB881 Multifunction Printer $265.99 1 1 Year Limited 1 x Automatic Document Feeder 40 Sheet 1 x Input Tray 250 Sheet 170 pages 21 25% 250 sheets 32 MB 33.6 4 sec/page 400% 600 dpi 600 x 1200 dpi 600 x 600 dpi 9600 x 9600 dpi 2-Bin Document Separator Flatbed multifunction laser printer with network connectivity functions as printer, copier, scanner and fax all in one unit. Two-Bin Separator can output faxes and copies into two separate trays. Printer/copier generates 22 pages per minute with 600 x 600 dpi. First copy is out in 17 seconds. 33.6Kbps fax modem transmits a page in 4 seconds, stores up to 170 pages in its built-in memory, and offers 300-speed dial stations and 150-page memory for out of paper reception. Flatbed color scanner features 600 x 1200 dpi optical resolution and 9600 x 9600 dpi interpolated resolution. Multifunction printer features 32MB memory, a 250-sheet paper cassette, 20-page document feeder, monitor speakerphone with dialing pad and copy scaling from 25 to 400 percent. USB 2.0 High-Speed and 10 Base-T/100 Base-TX interfaces are standard. Color Copier Desktop Fast Ethernet Fax Flatbed KX-FLB881 KX-FLB881 Multifunction Printer Laser Multifunction Printer Monochrome PC Panasonic Plain Paper Plain Paper Print Printer Scanner Yes www.panasonic.com |


US $99.00































































































