PC Review


Reply
Thread Tools Rate Thread

C# Guru's! ReadPrinter....I need to read printer buffer to stringbuilder...

 
 
trint
Guest
Posts: n/a
 
      15th Feb 2005
The WritePrinter() is working. I know this ReadPrinter()
implementation isn't correct because it never reads into "reaDstrinG"
buffer from the printer...But, I'm sure one of you Guru's do know how I
can make this work (and any help is appreciated):

string reaDstrinG = "";
int pcRead = 0;
for (int i = 0; i < 23; i++)
{
PrintDirect.ReadPrinter(lhPrinter,reaDstrinG,100,ref pcRead);
}


public class PrintDirect: Form1
{

PrintDirect PrDt = new PrintDirect();
public static extern long WritePrinter(IntPtr hPrinter,string data, int
buf,ref int pcWritten);
[ DllImport( "winspool.drv",CharSet=CharSet.Ansi,ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern long ReadPrinter(IntPtr hPrinter,string data,
int buf,ref int pcRead);
[ DllImport( "winspool.drv"
,CharSet=CharSet.Unicode,ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]

This is very important to me today.
Thanks,
Trint

 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      15th Feb 2005
> [ DllImport( "winspool.drv",CharSet=CharSet.Ansi,ExactSpelling=true,
> CallingConvention=CallingConvention.StdCall)]
> public static extern long ReadPrinter(IntPtr hPrinter,string data,
>int buf,ref int pcRead);


Use bool as the return type and make the data parameter a
StringBuilder.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Trint Smith
Guest
Posts: n/a
 
      15th Feb 2005
Mattias,
Do you mean the:
public static extern long ReadPrinter(IntPtr hPrinter,string data,int
buf,ref int pcRead);
should read:
public static extern long ReadPrinter(IntPtr hPrinter,string data,bool
buf,ref bool pcRead);
?
Thanks,
Trint


int buf,ref int pcRead);
Net programmer
(E-Mail Removed)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      15th Feb 2005
>Mattias,
>Do you mean the:
>public static extern long ReadPrinter(IntPtr hPrinter,string data,int
>buf,ref int pcRead);
>should read:
>public static extern long ReadPrinter(IntPtr hPrinter,string data,bool
>buf,ref bool pcRead);
>?


No, like this

public static extern bool ReadPrinter(IntPtr hPrinter, StringBuilder
data, int buf, out int pcRead);



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Trint Smith
Guest
Posts: n/a
 
      15th Feb 2005
Mattias,
I still am having troubles (I guess I don't understand how to get
reading from the printer), although writeprinter is working. Here is my
code that is not showing anything that I know is waiting to be sent from
the printer:
string reaDstrinG = "";
int buf = 0;
int pcRead;

System.Text.StringBuilder sb = new System.Text.StringBuilder();
PrintDirect.OpenPrinter(@"\\Web1\Shipping1",ref lhPrinter,0);
for (int i = -1; i < 23; i++)
{
PrintDirect.ReadPrinter(lhPrinter, sb.Append(reaDstrinG), buf, out
pcRead);
// PrintDirect.ReadPrinter(lhPrinter,reaDstrinG,buffLength,ref
pcRead);
}

Here is what is sent to the printer before this code (this is for a
status report on paper, staples and toner):

st1 = "\x1b%-12345X@PJL \f" +
"@PJL COMMENT ***Inquiring About \f" +
"@PJL COMMENT Environment Settings*** \f" +
@"@PJL ECHO " + formaTtd + " \f" +
"@PJL INQUIRE INTRAY2 \f" +
"@PJL INQUIRE INTRAY3 \f" +
"@PJL INQUIRE INTRAY4 \f" +
"@PJL INQUIRE STAPLER \f" +
"@PJL INQUIRE TONNER \f" +
"@PJL INQUIRE TIMEOUT \f" +
"@PJL ENTER LANGUAGE=PCL \f" +
"\x1b%-12345X\f";

Any help is really appreciated.
Thanks,
Trint

..Net programmer
(E-Mail Removed)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      18th Feb 2005

> PrintDirect.ReadPrinter(lhPrinter, sb.Append(reaDstrinG), buf, out
>pcRead);


That's a slightly weird call. You can just pass in sb as the second
parameter, you don't have to call Append there.

But the StringBuilder will not magically update reaDstrinG if that's
what you expect. You have to do reaDstrinG = sb.ToString() after the
API call.

If it still doesn't work, I suggest that you start checking the
function's return value.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
New Member
Join Date: Jun 2007
Posts: 1
 
      19th Jun 2007
Hi,
does anybody know how finally ReadPrinter should look like??

rafu
 
Reply With Quote
 
New Member
Join Date: Mar 2010
Posts: 1
 
      23rd Mar 2010
Try this:

[DllImport("winspool.Drv", EntryPoint = "ReadPrinter", SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]

public static extern bool ReadPrinter(
IntPtr hPrinter,
[MarshalAs(UnmanagedType.LPStr)] StringBuilder pBytes,
Int32 dwCount,
ref Int32 dwNReadBytes);
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why isn't there an StringBuilder.Append overload with StringBuilder as argument? cody Microsoft Dot NET 9 22nd Jul 2005 03:42 PM
read txtfile into string or stringbuilder or .Net dataTable? =?Utf-8?B?UmljaA==?= Microsoft VB .NET 4 8th Jun 2005 06:09 PM
REPOST: C# Guru's! ReadPrinter....I need to read printer buffer to stringbuilder... trint Microsoft C# .NET 6 16th Feb 2005 06:18 PM
StringBuilder's buffer unmanaged address Igor Microsoft C# .NET 1 18th Jul 2004 02:53 AM
Can a StringBuilder buffer be cleared? =?Utf-8?B?TWFyaWFubw==?= Microsoft VB .NET 3 20th Jan 2004 12:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:38 AM.