473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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,r ef 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

Nov 16 '05 #1
5 3657
> [ 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.
Nov 16 '05 #2
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
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
>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.
Nov 16 '05 #4
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,buffL ength,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
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
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.
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Mike Cox | last post by:
After writing an article trashing java, and C++, notable LISP guru Paul Graham is getting roasted on slashdot. Apart from AutoCAD and Emacs, what has LISP done anyway? Most real work is done in...
5
by: Raaijmakers, Vincent (IndSys,GE Interlogix) | last post by:
Looking at all the materials available, books, technologies etc etc.. I try to make a decision on what technology to select for a web server design, but I need help. I know, this question has...
4
by: Accolo1 | last post by:
Help we are looking for this person, do you know them? William wjohnson@accolo.com Title: BEA WebLogic Portal Guru Job #: 03-04468 Check the pulse of your career! Evolve our eCommerce web...
4
by: Marc Lawson | last post by:
Hi I consider myself a VB6 guru, but don't have much experience with VB.NET. I really want to get ramped up, but kind of don't know where to start Any suggestions on good books, sites, or...
3
by: Day Of The Eagle | last post by:
Jeff_Relf wrote: > ...yet you don't even know what RegEx is. > I'm looking at the source code for mono's Regex implementation right now. You can download that source here ( use the class...
2
by: Kalafiorczyk | last post by:
Good day ladies and gentlemen! I have a short proggie: ----------------------------------------------------------------------- #using <mscorlib.dll> using namespace...
3
by: Michael Suess | last post by:
Hi, please feel free to correct me if this is the wrong group to ask this question. I have a blog about parallel programming and concurrency (http://www.thinkingparallel.com if you are...
16
by: Singulus | last post by:
Hello all, I've searched for similar threads, I've found some bit of useful info here and there, but nevertheless I want to post my questions...So, how can I (we, in fact the forum can benefit...
1
by: stevenjs | last post by:
Greeings, all, Flash 8 has quiz templates which are coded for multiple choice, true/false, text statement, and matching types of questions, along with hotspots and probably anoher type I am...
4
by: Andrey | last post by:
Hi, I will be hiring a php guru to help us architect a highly scalable web site/web application; the problem is I am coming from Microsoft .NET world and not too much familiar with the platform....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.