日期:2014-05-19  浏览次数:20713 次

怎样输出到打印口(LPT1)!
大家好:
   
  以前用C++   时,直接用API  
CreateFile( "LPT1 ",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);

  请问在.NET下怎样输出打LPT1   谢谢!

------解决方案--------------------
在.net中直接用printdocument这个类来操作打印会更好些。
------解决方案--------------------
C#也可以调用API吧..
------解决方案--------------------
搜一下以前的帖子
------解决方案--------------------
到网上去找inpout.dll这个东西
或者自己用VC6.0写个DLL也可以,不过需要汇编的一点知识

------解决方案--------------------
[DllImport( "kernel32.dll ", CharSet = CharSet.Auto)]
private static extern IntPtr CreateFile(string lpFileName,
int dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile);


IntPtr iHandle = CreateFile( "LPT1 ", 0x40000000, 0, 0, 3, 0, 0);
FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default); //写数据
StringBuilder sb = new StringBuilder();
sb.Append((char)0x1B);
sb.Append((char)0x64);
sb.Append((char)0x0);//传入命令
sw.Write(sb.ToString());
sw.Close();
fs.Close();
CloseHandle(iHandle);