Web Images Maps Groups Scholar Blogs Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion ReadPrint Failure. How to use it properly
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
"Jeffrey Tan[MSFT]"  
View profile  
 More options Jul 11 2008, 5:23 am
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
can't read from a printer handle, but you can from a printer job handle. So
the trick is to create a Job using StartDocPrinter, then open a handle to
the printer job (which you can obtain by specifying the following syntax
for the printer name in OpenPrinter... "PrinterName,Job xxxx" (where xxxx
is a job id)).

Below is some test code that does this.

#define BUFSIZE 256
BOOL TestReadPrinterWithJob(LPSTR szPrinterName)
{
HANDLE hPrinter = NULL;
HANDLE hPrinterJob = NULL;
DWORD dwBytesRead;
LPVOID lpBytes = NULL;
DOC_INFO_1 dc;
DWORD jobid;
TCHAR jobStr[100];

// Open a handle to the printer.
if (!OpenPrinter(szPrinterName, &hPrinter, NULL))
{
PrintError(GetLastError(), "OpenPrinter");
return FALSE;

}

// 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
ClosePrinter(hPrinter);
if (lpBytes)
free(lpBytes);
return TRUE;

}

void PrintError( DWORD dwError, LPCSTR lpString )
{
#define MAX_MSG_BUF_SIZE 512
char *msgBuf;
DWORD cMsgLen;

cMsgLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER | 40, NULL, dwError,
MAKELANGID(0, SUBLANG_ENGLISH_US), (LPTSTR) &msgBuf, MAX_MSG_BUF_SIZE,
NULL);

printf( "%s Error [%d]:: %s\n", lpString, dwError, msgBuf );

LocalFree( msgBuf );
#undef MAX_MSG_BUF_SIZE

}

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
printer driver and a language monitor (both which are discussed in the DDK
(Driver Development Kit) documentation. The language monitor or port
monitor should already be using SetPrinter() and SetJob() to set the
printer and job status, which can then be read from an application with
GetPrinter() and/or GetJob(). <http://support.microsoft.com/?id=160129>
shows how to read the status, provided the monitor is setting it.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.asp...
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


    Reply to author    Forward  
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.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google