15,909,242 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member1345 (Top 10 by date)
Member1345
29-Mar-16 9:34am
View
please answer my question .
why do not answer my question some one ? its very important for me .
thank you so much
Member1345
26-Mar-16 18:59pm
View
What is your question?
Member1345
26-Mar-16 18:44pm
View
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess;
}
public static bool SendFileToPrinter(string szPrinterName, string szFileName)
{
FileStream stream1 = new FileStream(szFileName, FileMode.Open);
BinaryReader reader1 = new BinaryReader(stream1);
byte[] buffer1 = new byte[((int)stream1.Length) + 1];
buffer1 = reader1.ReadBytes((int)stream1.Length);
IntPtr ptr1 = Marshal.AllocCoTaskMem((int)stream1.Length);
Marshal.Copy(buffer1, 0, ptr1, (int)stream1.Length);
bool flag1 = RawPrinterHelper.SendBytesToPrinter(szPrinterName, ptr1, (int)stream1.Length);
Marshal.FreeCoTaskMem(ptr1);
return flag1;
}
public static void SendStringToPrinter(string szPrinterName, string szString)
{
IntPtr pBytes;
Int32 dwCount;
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemUni(szString);
SendBytesToPrinter(szPrinterName, pBytes, dwCount);
Marshal.FreeCoTaskMem(pBytes);
}
}
}
Member1345
26-Mar-16 18:41pm
View
hiThus, according to the changes made ، my new class is As follows :
note : this new class just print ascii characters and i still can not print unicode format . please some one help to change this class for print unicode format . SUCH AS (FARSI) OR (ARABIC) OR (URDO) OR MORE UNICODE ? It is very necessary and important for me ....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace AAA
{
public class RawPrinterHelperString
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode , Size= 4) ]
public struct DOCINFOW
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pDocName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pOutputFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
public static extern bool OpenPrinter(string src, ref IntPtr hPrinter, int pd);
[DllImport("winspool.Drv", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
public static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
public static extern bool StartDocPrinter(IntPtr hPrinter, int level, ref AAA.RawPrinterHelperString.DOCINFOW pDI);
[DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, int dwCount, ref int dwWritten);
public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
{
IntPtr hPrinter = System.IntPtr.Zero;
Int32 dwError;
DOCINFOW di = new DOCINFOW();
Int32 dwWritten = 0;
bool bSuccess;
di.pDocName = "My Document";
di.pDataType = "RAW";
bSuccess = false;
if (OpenPrinter(szPrinterName, ref hPrinter, (int)0))
{
if (StartDocPrinter(hPrinter, 1, ref di))
{
if (StartPagePrinter(hPrinter))
{
//MessageBox.Show(hPrinter.ToString() + "----" + pBytes + "----" + dwCount + "----" + dwWritten);
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
if (bSuccess == false)
{
dwError = Marshal.GetLastW
Member1345
26-Mar-16 18:38pm
View
hi
Thus, according to the changes made ، my new class is As follows :
note : this new class just print ascii characters and i still can not print unicode format . please some one help to change this class for print unicode format . SUCH AS (FARSI) OR (ARABIC) OR (URDO) OR MORE UNICODE ? It is very necessary and important for me ....
thank you so much ، thank you for your attention ...
Member1345
26-Mar-16 18:22pm
View
hi
meanwhile i changed the API to OpenPrinterA
StartDocPrinterA ، but this change Had no effect to unicode print .
Member1345
26-Mar-16 18:13pm
View
hi
(SendBytesToPrinter) method Is necessary (string szPrinterName,Intptr pBytes,int dwCount) . but you supplied (szPrinterName, encoded) if possible please tel me more why do you supply (szPrinterName, encoded) and tel me more how can i use from this method ?
Member1345
26-Mar-16 17:30pm
View
This code (RawPrinterHelperClass) works only for printing ascii characters. Can any one please help me to print unicode character SUCH AS (FARSI) OR (ARABIC) OR (URDO) OR MORE UNICODE ? It is very necessary and important for me ....
Thanks.
Member1345
26-Mar-16 17:08pm
View
hi . if possible tell me more how can i use The above procedure
(SendStringToPrinterUsingUnicode) for send a text file to printer directly ?
please If possible send to me modified class . It is very necessary and important for me ، thank you so much ...
Thank you for your attention .
Member1345
26-Mar-16 16:59pm
View
As regards arabicEncoding method in this class is useless ، so i deleted from class
but I am informing you that my file text Which must be printed is a file in utf-8 formatted . so this method is useless. please If possible you send to me modified class . It is very necessary and important for me . thank you so much ...
Show More