As part of the install to a project I need to create a Windows printer to print to a file that will then be faxed via a Linux server.
I have worked out that I need to use AddPrinterDriver first and then AddPrinter to create the printer but unfortunately I am a bit of a .NET newbie and can't get the following code for AddPrinter to work - it returns error 87 and the handle is some 16 digits long.
VB Code:
Private Overloads Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterA" _ (ByVal pName As String, ByVal Level As Long, _ <MarshalAs(UnmanagedType.LPStruct)> ByVal pPrinter As PRINTER_INFO_2) As Long Private Overloads Declare Function ClosePrinter Lib "winspool.drv" _ (ByVal hPrinter As Long) As Long <StructLayout(LayoutKind.Sequential)> Public Class PRINTER_INFO_2 Public pServerName As String Public pPrinterName As String Public pShareName As String Public pPortName As String Public pDriverName As String Public pComment As String Public pLocation As String Public pDevMode As Long Public pSepFile As String Public pPrintProcessor As String Public pDatatype As String Public pParameters As String Public pSecurityDescriptor As Long Public Attributes As Long Public Priority As Long Public DefaultPriority As Long Public StartTime As Long Public UntilTime As Long End Class Function CreatePrinter(ByVal strPrinter As String, ByVal strPort As String, _ ByVal strDriver As String) As Boolean Dim hPrinter As Long Dim PI2 As New PRINTER_INFO_2() With PI2 .pServerName = "" .pPrinterName = strPrinter .pShareName = "" .pPortName = strPort .pDriverName = strDriver .pComment = "" .pLocation = "" .pDevMode = 0 .pSepFile = "" .pPrintProcessor = "WinPrint" .pDatatype = "" .pParameters = "" .pSecurityDescriptor = 0 .Attributes = 0 .Priority = 0 .DefaultPriority = 0 .StartTime = 0 .UntilTime = 0 End With hPrinter = AddPrinter("", 2, PI2) If hPrinter <> 0 Then ClosePrinter(hPrinter) CreatePrinter = True Else CreatePrinter = False End If End Function
Any ideas on how to fix it?
chalkster




Reply With Quote