📄 howto send raw data to a printer by using the win32 api.htm
字号:
<LI style="PADDING-BOTTOM: 2px; PADDING-TOP: 0px">Microsoft
Windows 2000 , Advanced Server </LI></UL>
<UL style="MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px">
<LI style="PADDING-BOTTOM: 2px; PADDING-TOP: 0px">Microsoft
Windows 2000 , Server </LI></UL>
<UL style="MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px">
<LI style="PADDING-BOTTOM: 2px; PADDING-TOP: 0px">Microsoft
Windows 2000 , Professional </LI></UL><BR>
<HR>
<BR>
<H3>SUMMARY</H3>
<P>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 <B>SpoolFile() </B>methods
used in previous versions of the Windows API. </P><BR>
<H3>MORE INFORMATION</H3>
<P>
<H3>Sample Code </H3>You can use the following code to send raw data
directly to a printer in Windows NT or Windows 95. <PRE class=kbcode> // 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;
}
</PRE>The following file is available for download from the
Microsoft Download Center: <BR><BR>
<BLOCKQUOTE><A class=kblink
href="http://support.microsoft.com/default.aspx?scid=http://download.microsoft.com/download/platformsdk/Utility/95/WIN98/EN-US/RAWPRN.EXE"
target=_top>RAWPRN.EXE </A></BLOCKQUOTE>Release Date: February 10,
2000 <BR><BR>For additional information about how to download
Microsoft Support files, click the article number below to view the
article in the Microsoft Knowledge Base:
<BLOCKQUOTE><A class=kblink
href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q119591">Q119591</A>
How to Obtain Microsoft Support Files from Online Services
</BLOCKQUOTE>Microsoft used the most current virus detection
software available on the date of posting to scan this file for
viruses. Once posted, the file is housed on secure servers that
prevent any unauthorized changes to the file. <BR><BR><BR><BR>For
additional information about how to download Microsoft Support
files, click the article number below to view the article in the
Microsoft Knowledge Base:
<BLOCKQUOTE><A class=kblink
href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q119591">Q119591</A>
How to Obtain Microsoft Support Files from Online Services
</BLOCKQUOTE>Microsoft used the most current virus detection
software available on the date of posting to scan this file for
viruses. Once posted, the file is housed on secure servers that
prevent any unauthorized changes to the file. <BR><BR>
<P></P><BR>
<H3>REFERENCES</H3>
<P>For additional information, please see the following article in
the Microsoft Knowledge Base:
<BLOCKQUOTE><A class=kblink
href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q154078">Q154078</A>
HOWTO: SendRaw Data to a Printer Using the Win32 API from VB
</BLOCKQUOTE>
<P></P>
<HR>
<TABLE border=0 cellPadding=3 cellSpacing=1 width="95%">
<TBODY>
<TR>
<TD align=right vAlign=top width="10%" N0WRAP="1"><FONT size=1
NAME="Verdana, Arial, Helvetica"><B>Published</B></FONT></TD>
<TD><FONT size=1 NAME="Verdana, Arial, Helvetica">Oct 26 1995
12:00AM </FONT></TD>
<TD align=right noWrap vAlign=top width="10%"><FONT size=1
NAME="Verdana, Arial, Helvetica"><B>Issue Type</B></FONT></TD>
<TD><FONT size=1 NAME="Verdana, Arial, Helvetica">kbhowto
</FONT></TD></TR>
<TR>
<TD align=right noWrap vAlign=top width="10%"><FONT size=1
NAME="Verdana, Arial, Helvetica"><B>Last Modifed</B></FONT></TD>
<TD><FONT size=1 NAME="Verdana, Arial, Helvetica">Sep 7 2001
11:13AM </FONT></TD>
<TD align=right noWrap vAlign=top width="10%"><FONT size=1
NAME="Verdana, Arial, Helvetica"><B>Additional Query
Words</B></FONT></TD>
<TD><FONT size=1 NAME="Verdana, Arial, Helvetica">RAWPRN
RAW.DRV binary </FONT></TD></TR>
<TR>
<TD align=right vAlign=top width="10%" HOWRAP="1"><FONT size=1
NAME="Verdana, Arial, Helvetica"><B>Keywords</B></FONT></TD>
<TD colSpan=3><FONT size=1
NAME="Verdana, Arial, Helvetica">kbcode kbprint kbOSWinNT351
kbOSWin2000 kbPrinting kbSDKWin32 kbOSWin95 kbFAQ kbDSupport
kbGDIFAQ </FONT></TD></TR></TBODY></TABLE>
<HR>
<H3>COMMENTS?</H3>
<CENTER>
<FORM action=/support/contentvoting/voting_idc.asp method=post
name=VOTED onsubmit="return votingsubmit();">
<TABLE border=0 cellPadding=0 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD colSpan=2 vAlign=top><INPUT name=KBID type=hidden
value=138594></INPUT><INPUT name=PROD type=hidden
value=win32sdk></INPUT><INPUT name=KBAREA type=hidden
value="Support; KB;win32sdk"></INPUT><INPUT name=SRV
type=hidden value=support.microsoft.com></INPUT><INPUT name=QS
type=hidden value=scid=kb;en-us;Q138594></INPUT><INPUT
name=URL type=hidden value=/default.aspx></INPUT><INPUT
name=VOTE type=hidden value=1></INPUT>
<P>If you would like to briefly comment on this article, you
can enter your remarks in the space below (up to 255
characters).</P><TEXTAREA cols=40 id=COMMENTS name=COMMENTS rows=5 style="FONT-SIZE: x-small; FONT-STYLE: normal; FONT-VARIANT: normal; FONT-WEIGHT: normal; LINE-HEIGHT: normal; WIDTH: 90%" wrap=virtual></TEXTAREA>
<SCRIPT language=JavaScript>
function votingsubmit()
{
if(document.VOTED.COMMENTS.value.length == 0) {
alert("Please enter your remarks in the space provided.");
return false;
}
if(document.VOTED.COMMENTS.value.length > 255){
alert("Your comment has exceeded the 255 character limit.\nPlease reduce the number of characters in your comment.");
document.forms[0].COMMENTS.focus();
return false;}
else{
VOTED.submit();
return true;}
}
</SCRIPT>
<BR></TD></TR>
<TR>
<TD align=right noWrap><A
href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q138594&ID=kb;en-us;Q138594#"
onclick="votingsubmit();return false;"><B>Submit
Comments</B></A></TD>
<TD align=left width="10%"><INPUT align=absMiddle alt=Submit
border=0 hspace=12
src="HOWTO Send Raw Data to a Printer by Using the Win32 API_files/goright.gif"
type=image></TD></TR></TBODY></TABLE></FORM></CENTER><!-- - - - - - - - - - - - PAGE TEXT ENDS ABOVE HERE - - - - - - - - - - - --></FONT><BR></TD></TR></TBODY></TABLE></CENTER></TD></TR>
<TR>
<TD bgColor=#003399 colSpan=2 height=40 vAlign=center width="100%"
cellpadding="4">
<TABLE border=0 cellPadding=6 cellSpacing=0 height=40 width="100%">
<TBODY>
<TR>
<TD>
<TABLE border=0 cellPadding=0 cellSpacing=0 class=ftrmenutbl>
<TBODY>
<TR>
<TD><A class=buttontext
href="mailto:?body=http://support.microsoft.com/default.aspx?scid=kb;en-us;Q138594&ID=kb;en-us;Q138594"
onclick="" target=_top
title="Send the contents of this page to a Friend">Send <IMG
align=absMiddle border=0 hspace=0
src="HOWTO Send Raw Data to a Printer by Using the Win32 API_files/send_icon.gif"><IMG
border=0 height=1
src="HOWTO Send Raw Data to a Printer by Using the Win32 API_files/1ptrans.gif"
width=4></A></TD>
<TD vAlign=top><FONT class=buttontext>|</FONT> </TD>
<TD><A class=buttontext
href="HOWTO Send Raw Data to a Printer by Using the Win32 API_files/support.microsoft[1]"
onclick="if(document.getElementById) PrintContents(); else window.print(); event.cancelBubble=true; return false;"
target=_top
title="Print the contents of this page">Print <IMG
align=absMiddle border=0 hspace=0
src="HOWTO Send Raw Data to a Printer by Using the Win32 API_files/print_icon.gif"><IMG
border=0 height=1
src="HOWTO Send Raw Data to a Printer by Using the Win32 API_files/1ptrans.gif"
width=4></A></TD>
<TD vAlign=top><FONT class=buttontext>|</FONT> </TD>
<TD><A class=buttontext
href="http://support.microsoft.com/default.aspx?scid=fh;EN-GB;GSSHELP"
onclick="" target=_top
title="View information on how to use this site effectively">Help <IMG
align=absMiddle border=0 hspace=0
src="HOWTO Send Raw Data to a Printer by Using the Win32 API_files/help_icon.gif"><IMG
border=0 height=1
src="HOWTO Send Raw Data to a Printer by Using the Win32 API_files/1ptrans.gif"
width=4></A></TD>
<TR></TR></TBODY></TABLE><FONT class=cpyrigthtxt>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -