Newsgroups: microsoft.public.win32.programmer.gdi
From: je...@online.microsoft.com ("Jeffrey Tan[MSFT]")
Date: Fri, 11 Jul 2008 03:23:57 GMT
Local: Fri, Jul 11 2008 5:23 am
Subject: RE: ReadPrint Failure. How to use it properly
Hi Carlo ,
I have found an internal record discussing on a similar issue. In the record, our engineer found out through Windows source code that you Below is some test code that does this. #define BUFSIZE 256 // Open a handle to the printer. } // We can't read from a printer handle, but we can read from // a printer job handle, So the trick is to create a Job using // StartDocPrinter, then open a handle to the printer job... ZeroMemory(&dc, sizeof(DOC_INFO_1)); dc.pDocName="Dummy job"; jobid = StartDocPrinter(hPrinter,1,(LPSTR)&dc); // start a Doc if (jobid == 0) { ClosePrinter(hPrinter); PrintError(GetLastError(), "OpenPrinter"); return FALSE; } // Open handle to the printer job... wsprintf(jobStr, "%s,Job %i", szPrinterName, jobid); if (!OpenPrinter(jobStr, &hPrinterJob, NULL)) { ClosePrinter(hPrinter); PrintError(GetLastError(), "OpenPrinter Job"); return FALSE; } // Allocate a buffer to read printer data into... lpBytes = (LPVOID)malloc(BUFSIZE); if (!lpBytes) { PrintError(GetLastError(), "malloc"); ClosePrinter(hPrinter); ClosePrinter(hPrinterJob); return FALSE; } // Try ReadPrinter... SetLastError(0); if (!ReadPrinter(hPrinterJob, lpBytes, BUFSIZE, &dwBytesRead)) { PrintError(GetLastError(), "ReadPrinter"); ClosePrinter(hPrinter); ClosePrinter(hPrinterJob); if (lpBytes) free(lpBytes); return FALSE; } else { printf("%i bytes successfully read by ReadPrinter (%i attempted)\n", dwBytesRead, BUFSIZE); } // Clean up... ClosePrinter(hPrinterJob); EndDocPrinter(hPrinter); // end the doc } void PrintError( DWORD dwError, LPCSTR lpString ) { #define MAX_MSG_BUF_SIZE 512 char *msgBuf; DWORD cMsgLen; cMsgLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | printf( "%s Error [%d]:: %s\n", lpString, dwError, msgBuf ); LocalFree( msgBuf ); } So, the basic components necessary are a bidi-aware language monitor (i.e. one that implements ReadPort), the bidi checkbox checked for the printer properties, and a printer job handle returned from OpenPrinter (which implies that a job needs to exist). Before you can do bidirectional printing, you'll need to have a bidi-aware Hope this helps. Best regards, Delighting our customers is our #1 priority. We welcome your comments and Note: The MSDN Managed Newsgroup support offering is for non-urgent issues You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||