From: Carlo McKee on
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


From: Kellie Fitton on
On Jul 10, 3:03 pm, "Carlo McKee" <Logi...(a)newsgroup.nospam> wrote:
> 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



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.

From: Christoph Lindemann on
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" <Logical(a)newsgroup.nospam> wrote in message
news:%23LWpHjt4IHA.1192(a)TK2MSFTNGP05.phx.gbl...
>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
>