473,713 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,ExactSpel ling=true,
CallingConventi on=CallingConve ntion.StdCall)]
public static extern long WritePrinter(In tPtr hPrinter,string data, int
buf,ref int pcWritten);

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

WritePrinter(lh Printer,PCL5Com mands,PCL5Comma nds.Length,ref pcWritten);
thanks
shmuel


Jul 21 '05 #1
5 8698
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,ExactSpel ling=true,
CallingConventi on=CallingConve ntion.StdCall)]
public static extern long WritePrinter(In tPtr 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
servicescharset classtopic.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,ExactSpel ling=true,
CallingConventi on=CallingConve ntion.StdCall)]
public static extern long WritePrinter(In tPtr 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
servicescharset classtopic.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 SendBytesToPrin ter 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 SendBytesToPrin ter 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
4741
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 , setprinter . I did try with PrinterSetting.setHDevMode but it does not work. Its their is a simple way to change printersetting. thanks umesh.
0
295
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 winspool.drv. I was able to show the screen but my only problem is, as I have mentioned before,how to get the changes made by the user. Sample values are the number of pages, and orientation, etc.. by the way, the reason why I want to retrieve...
0
2373
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)> _ Public Structure DOCINFO<MarshalAs(UnmanagedType.LPWStr)> Public pDocName As String<MarshalAs(UnmanagedType.LPWStr)>
1
4546
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 PRINTER_ACCESS_ADMINISTER = 4 PRINTER_ACCESS_USE = 8 PRINTER_ALL_ACCESS = 98305 string strPrinterName, out IntPtr phPrinter, ref PRINTER_DEFAULTS pdDefaults)
1
4886
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 the functions. So, is there a way? Paul M.
1
1181
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 send the macro byte by byte to the printer. The problem is the printer views this as a print job rather than a macro that should be loaded into printer memory. So after a minute or two it delets and or spits out the printjob rather than keeping...
4
348
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 long WritePrinter(IntPtr hPrinter,string data, int buf,ref int pcWritten); string PCL5Commands = "<esc>(15H<esc>(s0p12.00h10.1h0s0b4102T <hebrew
2
1891
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 able to print postscript and pdf directly. I've looked in to sending the pdf to the printer as a byte array (via winspool driver), but this doesnt have a way to select which tray. Also, i've looked at using System.Drawing.Printing, which lets you...
2
6717
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 of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working. Option Explicit Private Type DOCINFO pDocName As String pOutputFile As String pDatatype As String
0
8794
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8701
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9300
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9066
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7939
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3154
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2101
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.