printing with pcl using winspool.drv

G

Guest

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.Length,ref pcWritten);
thanks
shmuel
 
S

Steven Cheng[MSFT]

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-us/cpref/html/frlrfsystemruntimeinterop
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.)
 
G

Guest

I Steven
thnxs for the repley,
If i try to change the CharSet it does not print at all
 
K

Kevin Yu [MSFT]

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."
 
K

Kevin Yu [MSFT]

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top