home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / print.c < prev    next >
Text File  |  2020-01-01  |  2KB  |  69 lines

  1. You can use the following code to send raw data directly to a printer in
  2. Windows NT or Windows 95.
  3.  
  4. // RawDataToPrinter - sends binary data directly to a printer
  5. //
  6. // Params:
  7. //   szPrinterName - NULL terminated string specifying printer name
  8. //   lpData        - Pointer to raw data bytes
  9. //   dwCount       - Length of lpData in bytes
  10. //
  11. // Returns: TRUE for success, FALSE for failure
  12. //
  13. BOOL RawDataToPrinter( LPSTR szPrinterName, LPBYTE lpData, DWORD dwCount )
  14. {
  15.   HANDLE     hPrinter;
  16.   DOC_INFO_1 DocInfo;
  17.   DWORD      dwJob;
  18.   DWORD      dwBytesWritten;
  19.  
  20.   // Need a handle to the printer
  21.   if( ! OpenPrinter( szPrinterName, &hPrinter, NULL ) )
  22.     return FALSE;
  23.  
  24.   // Fill in the structure with info about this "document"
  25.   DocInfo.pDocName = "My Document";
  26.   DocInfo.pOutputFile = NULL;
  27.   DocInfo.pDatatype = "RAW";
  28.   // Inform the spooler the document is beginning
  29.   if( (dwJob = StartDocPrinter( hPrinter, 1, (LPSTR)&DocInfo )) == 0 )
  30.   {
  31.     ClosePrinter( hPrinter );
  32.     return FALSE;
  33.   }
  34.   // Start a page
  35.   if( ! StartPagePrinter( hPrinter ) )
  36.   {
  37.     EndDocPrinter( hPrinter );
  38.     ClosePrinter( hPrinter );
  39.     return FALSE;
  40.   }
  41.   // Send the data to the printer
  42.   if( ! WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten ) )
  43.   {
  44.     EndPagePrinter( hPrinter );
  45.     EndDocPrinter( hPrinter );
  46.     ClosePrinter( hPrinter );
  47.     return FALSE;
  48.   }
  49.   // End the page
  50.   if( ! EndPagePrinter( hPrinter ) )
  51.   {
  52.     EndDocPrinter( hPrinter );
  53.     ClosePrinter( hPrinter );
  54.     return FALSE;
  55.   }
  56.   // Inform the spooler that the document is ending
  57.   if( ! EndDocPrinter( hPrinter ) )
  58.   {
  59.     ClosePrinter( hPrinter );
  60.     return FALSE;
  61.   }
  62.   // Tidy up the printer handle
  63.   ClosePrinter( hPrinter );
  64.   // Check to see if correct number of bytes writen
  65.   if( dwBytesWritten != dwCount )
  66.     return FALSE;
  67.   return TRUE;
  68. }
  69.