声明为:
[DllImport("winspool.Drv", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
public static extern bool WritePrinter(IntPtr hPrinter, byte[] pBytes, int dwCount, ref int dwWritten);
调用:
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten); 但是只要打印内容是中文出来的就是乱码,英文字母和数字则没有问题
请问各位高手 怎么解决
[DllImport("winspool.Drv", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
public static extern bool WritePrinter(IntPtr hPrinter, byte[] pBytes, int dwCount, ref int dwWritten);
调用:
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten); 但是只要打印内容是中文出来的就是乱码,英文字母和数字则没有问题
请问各位高手 怎么解决
这个api用的是本机编码的吧,windows问unicode
在形成byte[]时用Encoding的unicode编码,
不行的话再用用别的编码形式试试
public static bool SendBytesToPrinter(string szPrinterName, byte[] pBytes, Int32 dwCount)
{
IntPtr hPrinter = System.IntPtr.Zero;
Int32 dwError;
DOCINFOW di = new DOCINFOW();
Int32 dwWritten = 0;
bool bSuccess;
di.pDocName = "Document";
di.pDataType = "RAW";
bSuccess = false;
if (OpenPrinter(szPrinterName,ref hPrinter, 0))
{
if (StartDocPrinter(hPrinter, 1,ref di))
{
if (StartPagePrinter(hPrinter))
{
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess; } public static void SendStringToPrinter(string szPrinterName, string szString)
//调用
{
IntPtr pBytes;
Int32 dwCount;
byte [] f=Encoding.Unicode.GetBytes(szString);
dwCount = f.Length;
SendBytesToPrinter(szPrinterName, f, dwCount);
}
可是打出来还是不行
如果是打印机的问题
谁知道西铁城的GSX-230
的设置方法
没找到说明书
用WOOD打印中文没有问题
网上有相关类,你找一下就好另外如果你用的西铁城的话,必须找他的手册 如果不写口,
直接用OPOS就好了
在C#写几句话就完了,但速度肯定没有写口的快.