473,387 Members | 1,766 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,387 software developers and data experts.

printing with pcl using winspool.drv


I am trying to print directly to an HP printer using winspool.drv API.
when I try English every thing works fine, when i try hebrew, I got garbge.
any suggestions?

code:
[ DllImport( "winspool.drv",CharSet=CharSet.Ansi,ExactSpelling= true,
CallingConvention=CallingConvention.StdCall)]
public static extern long WritePrinter(IntPtr hPrinter,string data, int
buf,ref int pcWritten);

string PCL5Commands = "<esc>(15H<esc>(s0p12.00h10.1h0s0b4102T <hebrew
letters> ";

WritePrinter(lhPrinter,PCL5Commands,PCL5Commands.L ength,ref pcWritten);
thanks
shmuel


Jul 21 '05 #1
5 8636
Hi Shmuel,

Welcome to MSDN newsgroup.
As for the PInvoke problem you mentioned , based on my experience, it's
likely due to the Charset you set in the function declaration. As you've
pasted in the former message , you used the following function declaration:

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

CharSet=CharSet.Ansi, means the runtime will use the ANSI code page to
convert the .net's unicode string, so when there're non-ascii chars, .net
will use the machine's System Locale to convert the string into Multi Byte
chars. So as for the
hebrew letters, if your machine's System Locale is not set to a correct
hebrew charset , the result chars will become corrupted. I think you can
try changing the Charset to CharSet.Unicode or CharSet.Auto :

1. CharSet.Uncode means runtime will convert string to wide chars(in
unmanaged code)

2. CharSet.Auto means runtime will determine whether to convert string into
Wide Chars or MUlti Bytes chars according to the machine support for
unicode.

For more detail info, you can refer to the following msdn document:

#CharSet Enumeration
http://msdn.microsoft.com/library/en...runtimeinterop
servicescharsetclasstopic.asp?frame=true

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 21 '05 #2
I Steven
thnxs for the repley,
If i try to change the CharSet it does not print at all
--
moital
"Steven Cheng[MSFT]" wrote:
Hi Shmuel,

Welcome to MSDN newsgroup.
As for the PInvoke problem you mentioned , based on my experience, it's
likely due to the Charset you set in the function declaration. As you've
pasted in the former message , you used the following function declaration:

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

CharSet=CharSet.Ansi, means the runtime will use the ANSI code page to
convert the .net's unicode string, so when there're non-ascii chars, .net
will use the machine's System Locale to convert the string into Multi Byte
chars. So as for the
hebrew letters, if your machine's System Locale is not set to a correct
hebrew charset , the result chars will become corrupted. I think you can
try changing the Charset to CharSet.Unicode or CharSet.Auto :

1. CharSet.Uncode means runtime will convert string to wide chars(in
unmanaged code)

2. CharSet.Auto means runtime will determine whether to convert string into
Wide Chars or MUlti Bytes chars according to the machine support for
unicode.

For more detail info, you can refer to the following msdn document:

#CharSet Enumeration
http://msdn.microsoft.com/library/en...runtimeinterop
servicescharsetclasstopic.asp?frame=true

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Jul 21 '05 #3
Hi moital,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4
Hi moital,

To send raw data to printer using C#, you can first check the following KB
article.

http://support.microsoft.com/?id=322091

Based on my research, Unicode is not supported to be passed to the printer
directly. So in this case, you can try to use GDI or System.Drawing to
convert the text to raw data and use SendBytesToPrinter to print it.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #5
Hi moital,

To send raw data to printer using C#, you can first check the following KB
article.

http://support.microsoft.com/?id=322091

Based on my research, Unicode is not supported to be passed to the printer
directly. So in this case, you can try to use GDI or System.Drawing to
convert the text to raw data and use SendBytesToPrinter to print it.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #6

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

Similar topics

4
by: Umesh | last post by:
Hi all I am trying to change the printer(like paper source ,etc) setting in C#. But i am unable to do it. I am not sure how to do it. should i have to use WIN API like Openprinter , getprinter ,...
0
by: sparton | last post by:
Good day!! Is there a way to retrieve values / changes from documentproperties? documentproperties is the screen is shown when you press 'properties' on the 'Print' window. This can be derived from...
0
by: Chris | last post by:
Hi, I found this code to send print direct to printer. It works perfect. Imports System Imports System.Text Imports System.Runtime.InteropServices <StructLayout(LayoutKind.Sequential)> _...
1
by: faktujaa | last post by:
Hi ALL Please check the code below. OpenPrinter method returns Access is Denied error. Serial Printer is connected to the the IP address with name given at COM1 public enum ACCESS_MAS ...
1
by: Paul M. | last post by:
Hi Everyone, I would like to use some of the Win32 printer functions in C# but they are in Winspool.lib. I was hoping that there is a way to do this without writing a dll in C++ and importing...
1
by: Shane | last post by:
I am trying to print a macro which is really just a bunch of pcl code that represents a form of mine to the printer. I have been able to do this using the winspool.drv api calls so that I can...
4
by: moital | last post by:
I am trying to print directly to an HP printer using winspool.drv API. when I try English every thing works fine, when i try hebrew, I got garbge. any suggestions? code: public static extern...
2
by: koa2 | last post by:
I've been looking for a way to print a PDF as easily and as cheap as possible. also, (the compicated part) i need to be able to select which tray is used on the printer. The printers being used are...
2
by: Flying Kite | last post by:
Hi All, I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.