IMPRIMIR DIRECTAMENTE EN "LPT1" SIN UTILIZAR UN FICHERO TEMPORAL

04/11/2004 - 09:05 por JuanmaX | Informe spam
Me gustaria saber como imprimir directamente sobre el LPT1 o un COM (en
VB.Net) sin necesidad de ficheros de TXT temporales.

En Visual Basic se puede, pero al importar ese proyecto a .net me da un
error.

MuchasGracias.

Preguntas similare

Leer las respuestas

#1 Tristan
04/11/2004 - 11:00 | Informe spam
Para enviar texto directamente a la impresora (aunque
deberías evitarlo siempre que sea posible) debes obtener
un stream que apunte al puerto. De momento, solo podrás
hacerlo mediante el api win32 CreateFile:


Dim lpt1 As StreamWriter = GetStreamWriter("LPT1")
lpt1.WriteLine("Texto directo")
lpt1.Close()



Const GENERIC_WRITE As Int32 = &H40000000
Const OPEN_EXISTING As Int32 = 3

Public Declare Auto Function CreateFile
Lib "kernel32.dll" (ByVal lpFileName As String, ByVal
dwDesiredAccess As Integer, ByVal dwShareMode As Integer,
ByVal lpSecurityAttributes As IntPtr, ByVal
dwCreationDisposition As Integer, ByVal
dwFlagsAndAttributes As Integer, ByVal hTemplateFile As
IntPtr) As IntPtr

Private Function GetStreamWriter(ByVal port As String) As
StreamWriter
Dim hFich As IntPtr = CreateFile(port, GENERIC_WRITE,
0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
Dim stream As New FileStream(hFich, FileAccess.Write)
Dim writer As New StreamWriter(stream)
Return writer
End Function

Juan Carlos Badiola
MVP - C#
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida