Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Retrieving Data from printer using ReadPrinter API

693 views
Skip to first unread message

Carlo McKee

unread,
Jul 10, 2008, 6:03:29 PM7/10/08
to
I am trying to retrieve data from a bidirectional printer using the
ReadPrint API function.
The printer I am using is connected via USB.
Issue:

The ReadPrint function is returning false. The error code retrieved by
GetLastError is 6 (ERR_INVALID_HANDLE).

Before I use ReadPrint I create a printer handle using the OpenPrint API
function which returns true. Immediately after the OpenPrinter returns I
check if my handle is not invalid and is not. Below is a snippet of my
calls.


//The open printer does return true.
if(!OpenPrinter(( (LPTSTR)(pPrinterName)), &hPrinter, NULL ) )
{
DisplayError(GetLastError(),"GetPrinterStatus: OpenPrinter");
return (FALSE);
}

//I check if I have a Valid Handle and I do
if (hPrinter == INVALID_HANDLE_VALUE)
{
DisplayError(GetLastError(), "GetPrinterStatus: hPrinter invalid");
return (FALSE);
}

//Now that Open the printer and I have a handle I use ReadPrint
//This function actually returns false. The GetLastError is 6
(ERR_INVALID_HANDLE)
//But why is invalid handle if the OpenPrinter gave me a valid handle
if (!ReadPrinter(hPrinter, &Status, 16, &bytesRead))
{
DisplayError( GetLastError(), "GetPrinterStatus: ReadPrinter) );
return (FALSE);
}

I am positive I am getting a good handle from the OpenPrinter since I can
use OpenPrinter to write to the printer using the WritePrinter API. I can
successfully print using WritePrinter but fail to ReadPrinter.

Please advice what I may doing wrong or is there any other API to get data
from a printer.

Thank you


Kellie Fitton

unread,
Jul 10, 2008, 10:54:08 PM7/10/08
to

Hi,

You can use the following API to retrieve information
about a specified printer:

GetPrinter()

http://msdn.microsoft.com/en-us/library/ms535494(VS.85).aspx

Kellie.

Christoph Lindemann

unread,
Jul 22, 2008, 4:35:31 AM7/22/08
to
Hi Carlo,

You can not use ReadPrinter to read data from a Windows printer object.
Actually what you want is read from the "port" not the "printer". But that
also is not permitted (unless you are a "language monitor"). You can use the
"Bidi communication interface" (if the current language monitor supports
this)

Your best choice when using USB, is to open the USB port directly


--
Christoph Lindemann
Undocumented Printing
http://www.undocprint.org/


"Carlo McKee" <Log...@newsgroup.nospam> wrote in message
news:%23LWpHjt...@TK2MSFTNGP05.phx.gbl...

0 new messages