There are few question from the following code which i came across here:
// RawDataToPrinter - sends binary data directly to a printer
//
// 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(LPTSTR szPrinterName, LPBYTE lpData, DWORD dwCount)
{
BOOL bStatus = FALSE;
HANDLE hPrinter = NULL;
DOC_INFO_1 DocInfo;
DWORD dwJob = 0L;
DWORD dwBytesWritten = 0L;
// Open a handle to the printer.
bStatus = OpenPrinter( szPrinterName, &hPrinter, NULL ); // question 1
if (bStatus) {
// Fill in the structure with info about this "document."
DocInfo.pDocName = (LPTSTR)_T("My Document"); // question 2
DocInfo.pOutputFile = NULL; // question 3
DocInfo.pDatatype = (LPTSTR)_T("RAW"); // question 4
// Inform the spooler the document is beginning.
dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo ); // question 5
if (dwJob > 0) {
// Start a page.
bStatus = StartPagePrinter( hPrinter );
if (bStatus) {
// Send the data to the printer.
bStatus = WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten);
EndPagePrinter (hPrinter);
}
// Inform the spooler that the document is ending.
EndDocPrinter( hPrinter );
}
// Close the printer handle.
ClosePrinter( hPrinter );
}
// Check to see if correct number of bytes were written.
if (!bStatus || (dwBytesWritten != dwCount)) {
bStatus = FALSE;
} else {
bStatus = TRUE;
}
return bStatus;
}
Please look for the question number in comments
Question 1
- when i have set
hPrinter = nullthen what is meant by&hPrinter?
Question 2
- what does
(LPTSTR)_Tdenote ? (see T )
Question 3
- What does null here denote ?
Question 4
- What does
RAWmean ( what type of data it is ? ) ?
Question 5
- What does
1denote here ?
&hPrinteris the address of thehPrintervariable. You need to pass it so theOpenPrinterfunction can write in it the actual handle to the printer._Ttakes your character string and converts it to the proper ANSI (8bits/character) or Unicode (16bits/character) representation based on your compilation settings. Basically it’s a macro that either expands to nothing (ANSI) orL(Unicode) plus the actual string.Here where, in the code?
NULLis a macro that expands to (basically)0. It’s used to provide a decent default value.Raw data is exactly what it sounds, raw data. It’s not structured in any way, it’s just a soup of bytes you pass to a (usually) device.
From http://msdn.microsoft.com/en-us/library/dd145115(v=vs.85).aspx: