|
-
Jul 13th, 2001, 09:38 AM
#1
Thread Starter
Junior Member
Print Device Context
I need to create a print device context to a computers default computer.
Here is the code I'm using right now, but it doesn't work. It seems to be breaking at the EnumPrinters function. Can somebody please help me?
Dim hPrintDC As Long ' handle to the printer's device context
Dim di As DOCINFO ' information about the document to print
Dim buffer(0 To 3076 / 4) As Long ' 3076-byte buffer
Dim pi2 As PRINTER_INFO_2 ' receives info about the default printer
Dim printret As Long ' receives the number of printers returned from EnumPrinters
Dim spaceneeded As Long ' receives space requires for EnumPrinters
Dim retval As Long ' return value
Dim fileName As String
Dim cnt As Integer
' Get the device and driver names of the default printer. For a more detailed
retval = EnumPrinters(PRINTER_ENUM_DEFAULT, "", 2, buffer(0), 3076, spaceneeded, printret)
If retval = 0 Then
Debug.Print "No default printer is configured."
End ' abort the program
End If
' Copy the device and driver names to the structure. All the
' other information retrieved is not needed and is omitted here.
pi2.pPrinterName = Space(lstrlen(buffer(1)))
retval = lstrcpy(pi2.pPrinterName, buffer(1))
pi2.pDriverName = Space(lstrlen(buffer(4)))
retval = lstrcpy(pi2.pDriverName, buffer(4))
' Create a device context to the printer, using its default initialization.
hPrintDC = CreateDC("", pi2.pPrinterName, 0, ByVal CLng(0))
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
|