Http://support.microsoft.com/kb/322091/zh-cn? Spid = 548 & SID = 348 # top
It seems that the official support of Microsoft has provided the VC # solution, which can be run, and no error is reported, that is, there is no response!
The basic function call process is binary,
Openprinter --> startdocprinter --> startpageprinter --> writeprinter --> endpageprinter --> enddocprinter --> closeprinter
Explanations of various functions:
Openprinter:
The openprinter function gets a handle to another type of handle in the specified printer, print server, or print subsystem.
Bool openprinter (
Lptstr pprintername, // printer or server name
Lphandle phprinter, // printer or server handle
Lpprinter_defaults pdefault // printer defaults
);
Parameters:
Pprintername: [input parameter] non-null string, indicating the printer name;
Phprinter: [Output] receives the handle of the opened printer;
Pdefault: [input] pointer to the printer_defaults structure. This value can be null.
Return Value:
If the function succeeds, the return value is a non-zero value. If the function fails, the return value is zero. Call getlasterror to obtain more error information.
Note:
Do not call this method in dllmain. Non-thread-safe, multi-threaded operations must be synchronized.
Startdocprinter
The startdocprinter function notifies Spooler that a file has been spooled for printing.
DWORD startdocprinter (
Handle hprinter, // handle to printer object
DWORD level, // information level
Lpbyte pdocinfo // information Buffer
);
Parameters
Hprinter: printer handle;
Level: the structure of the specified version. pdocinfo points to this structure. In Windows NT/2000/XP, This value must be 1. in Windows 95/98/Me, this value can be 1 or 2;
Pdocinfo: a pointer to a structure that describes the file to be printed. In Windows NT/2000/XP, pdocinfo is a pointer to the doc_info_1 structure. In Windows 95/98/Me, pdocinfo is a pointer to the doc_info_1 or doc_info_2 structure.
Doc_info_1 structure:
Typedef struct _ doc_info_1 {
Lptstr pdocname;
Lptstr poutputfile;
Lptstr pdatatype;
} Doc_info_1;
Startpageprinter: Notifies Spooler that a page will be printed on the specified printer.
Writeprinter:
The writeprinter function notifies splooer that data should be written to the specified printer.
Bool writeprinter (
Handle hprinter, // handle to printer object
Lpvoid pbuf, // array of printer data
DWORD cbbuf, // size of Array
Lpdword pcwritten // bytes written to printer
);
Parameters:
Hprinter: [input] printer handle;
Pbuf: [input] a pointer to a byte array, which contains the data to be written to the printer.
Cbbuf: [input] the size of the array, in bytes.
Pcwritten: pointer to the [Output] value, which stores the length of the array written to the printer.