469,282 Members | 1,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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 8367
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Umesh | last post: by
reply views Thread by Chris | last post: by
1 post views Thread by faktujaa | last post: by
1 post views Thread by Paul M. | last post: by
1 post views Thread by Shane | last post: by
4 posts views Thread by moital | last post: by
2 posts views Thread by koa2 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.