• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 76
  • Last Modified:

Printer Properties Displayed is Incomplete

I wish to show the properties of a printer. The common dialog control cannot manage this so using some code calling API's. It does bring up the Properties Window but for some peculiar reason only show the last tab page.

I am using VB6/Win 10

Declare Function PrinterProperties Lib "winspool.drv" (ByVal hwnd As Long, ByVal hPrinter As Long) As Long
Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long

    pDatatype As String
    pDevMode As Long
    pDesiredAccess As Long
End Type

Private Sub cmdShowPrinter_Click()
   Call ShowPrinterProperties("Canon MG6100 series Printer WS", Me.hwnd)
End Sub

Private Sub ShowPrinterProperties(ByVal DeviceName As String, ByVal ParentHWnd As Long)
    On Error GoTo ErrHandler
    Dim PrinterDef As PRINTER_DEFAULTS
    Dim hPrinter As Long
    Dim lngPrinter As Long
    Const DELETE = &H10000
    Const READ_CONTROL = &H20000          ' Allowed to read device information
    Const WRITE_DAC = &H40000             ' Allowed to write device access control info
    Const WRITE_OWNER = &H80000           ' Allowed to change the object owner
    ' Combining these for full access to a device  (DELETE + READ_CONTROL + WRITE_DAC + WRITE_OWNER):
    Const SERVER_ACCESS_ADMINISTER = &H1  ' Access rights to administer print servers.
    Const SERVER_ACCESS_ENUMERATE = &H2   ' Access rights to enumerate print servers.
    Const PRINTER_ACCESS_ADMINISTER = &H4 ' Access rights for printers to perform administrative tasks.
    Const PRINTER_ACCESS_USE = &H8        ' Access rights for printers for general use (printing, querying).
    ' Access which allows you to set duplex on or off
    PrinterDef.pDesiredAccess = PRINTER_NORMAL_ACCESS
    PrinterDef.pDevMode = True
    If OpenPrinter(DeviceName, hPrinter, PrinterDef) Then
        lngPrinter = PrinterProperties(ParentHWnd, hPrinter)
        ClosePrinter hPrinter
    End If
    Exit Sub

If hPrinter <> 0 Then ClosePrinter hPrinter

End Sub

Open in new window

What I am getting through the code:
Single Tab Printer Properties
What it should be showing:
True Multi Tab Printer Properties
Any help would be much appreciated
Edward Cooper
Edward Cooper
  • 3
1 Solution
Claire StrebSoftware GuruCommented:

I'm not sure what PrinterDef.pDevMode = True is attempting to do?  According to the doc (https://msdn.microsoft.com/en-us/library/windows/desktop/dd162839%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396), PRINTER_DEFAULTS.pDevMode is a pointer to a structure.  Did you just copy the code from here (http://www.devx.com/vb2themax/Tip/18895) and expect it to work without reading the documentation by any chance?  Similarly, the code from here (http://www.freevbcode.com/ShowCode.asp?ID=558) simply sets pDevMode to zero, so you could try that if you don't want to set up your structure, but I don't guarantee it will work.  In other words, OpenPrinter(DeviceName, hPrinter, ByVal 0&),

Dan Appleman's "Visual Basic Programmer's Guide to the API" is a great reference!

Anyway, regardless,  if you can't get this to work, you might try a shellexec to rundll.exe on the PRINTUI.DLL.  You can find a lot of information about that on Rob van der Woude's Scripting Pages (http://www.robvanderwoude.com/2kprintcontrol.php).

Hope this Helps,
Edward CooperDirectorCommented:
Hello Claire

Thanks for your response. I did get that and other code from either those sites or similar. Your suggestion of using a try OpenPrinter(DeviceName, hPrinter, ByVal 0&), blew a gasket and in fact any attempting setting of pDataType either crashes vb6 or else simply doesn't do anything.

Working through the scripting options may be the way to go and I am just trialling that now. I have come across a solution at groups.google.com/forum/#!topic/microsoft.public.vb.controls/vda3CbgGQUI. I will let you know how this goes.

Many thanks
Claire StrebSoftware GuruCommented:
Hi Edward,

Yes, the google URL you gave is setting the structure as I advised from https://msdn.microsoft.com/en-us/library/windows/desktop/dd162839%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396.  

Hope it works for you!
Claire StrebSoftware GuruCommented:
Glad I could help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now