|
-
Oct 7th, 2003, 07:09 AM
#1
Thread Starter
New Member
Adding a printer
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
-
Oct 7th, 2003, 03:44 PM
#2
Frenzied Member
I think you have to replace 'Long' with "integer', in your APIs, and maybe in the PRINTER_INFO_2 class. Try and see if it addresses the issue.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 6th, 2004, 06:32 AM
#3
Lively Member
did u ever resolve this? it would save me some time rather then manually adding my print to file printer
-
Jan 6th, 2004, 01:33 PM
#4
Thread Starter
New Member
In the end I used the PrintUI.dll using the Shell command.
See www.robvanderwoude.com/2kprintcontrol.html - although this only works on NT based Windows - ie 2000 and XP.
chalkster
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|