You are currently offline, waiting for your internet to reconnect

HOWTO: Send Raw Data to a Printer by Using the Win32 API

It is sometimes necessary to send printer-specific data directly to a printer, bypassing the driver. The Win32 API provides a do it that works on local and networked printers. This method can be used to replace the PASSTHROUGH escape and SpoolFile() methods used in previous versions of the Windows API.
More information

Sample Code

You can use the following code to send raw data directly to a printer in Windows NT or Windows 95.
   // RawDataToPrinter - sends binary data directly to a printer   //    // Params:   //   szPrinterName - NULL terminated string specifying printer name   //   lpData        - Pointer to raw data bytes   //   dwCount       - Length of lpData in bytes   //    // Returns: TRUE for success, FALSE for failure.   //    BOOL RawDataToPrinter(LPSTR szPrinterName, LPBYTE lpData, DWORD dwCount)   {     HANDLE     hPrinter;     DOC_INFO_1 DocInfo;     DWORD      dwJob;     DWORD      dwBytesWritten;     // Need a handle to the printer.     if( ! OpenPrinter( szPrinterName, &hPrinter, NULL ) )       return FALSE;     // Fill in the structure with info about this "document."     DocInfo.pDocName = "My Document";     DocInfo.pOutputFile = NULL;     DocInfo.pDatatype = "RAW";     // Inform the spooler the document is beginning.     if( (dwJob = StartDocPrinter( hPrinter, 1, (LPSTR)&DocInfo )) == 0 )     {       ClosePrinter( hPrinter );       return FALSE;     }     // Start a page.     if( ! StartPagePrinter( hPrinter ) )     {       EndDocPrinter( hPrinter );       ClosePrinter( hPrinter );       return FALSE;     }     // Send the data to the printer.     if( ! WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten ) )     {       EndPagePrinter( hPrinter );       EndDocPrinter( hPrinter );       ClosePrinter( hPrinter );       return FALSE;     }     // End the page.     if( ! EndPagePrinter( hPrinter ) )     {       EndDocPrinter( hPrinter );       ClosePrinter( hPrinter );       return FALSE;     }     // Inform the spooler that the document is ending.     if( ! EndDocPrinter( hPrinter ) )     {       ClosePrinter( hPrinter );       return FALSE;     }     // Tidy up the printer handle.     ClosePrinter( hPrinter );     // Check to see if correct number of bytes were written.     if( dwBytesWritten != dwCount )       return FALSE;     return TRUE;   }				
The following file is available for download from the Microsoft Download Center:

Release Date: February 10, 2000

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

For additional information, please see the following article in the Microsoft Knowledge Base:
154078 HOWTO: SendRaw Data to a Printer Using the Win32 API from VB

Article ID: 138594 - Last Review: 06/22/2014 17:58:00 - Revision: 5.0

  • kbdownload kbcode kbFAQ kbhowto kbprint KB138594
t('meta');'ms.dqp0';m.content='true';document.getElementsByTagName('head')[0].appendChild(m);" onload="var m=document.createElement('meta');'ms.dqp0';m.content='false';document.getElementsByTagName('head')[0].appendChild(m);" src=""> DI=4050&did=1&t=">