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

Public Type PRINTER_DEFAULTS
    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 PRINTER_ALL_ACCESS = &HF000C
    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 STANDARD_RIGHTS_REQUIRED = &HF0000
     
    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
    Const PRINTER_NORMAL_ACCESS = (READ_CONTROL Or PRINTER_ACCESS_USE Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ALL_ACCESS Or WRITE_OWNER)
 
    PrinterDef.pDesiredAccess = PRINTER_NORMAL_ACCESS
    PrinterDef.pDevMode = True
    If OpenPrinter(DeviceName, hPrinter, PrinterDef) Then
        lngPrinter = PrinterProperties(ParentHWnd, hPrinter)
        ClosePrinter hPrinter
    End If
    
    Exit Sub
    
ErrHandler:


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 CooperDirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Claire StrebSoftware GuruCommented:
Hi,

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,
Claire
0
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
Edward
0
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Claire StrebSoftware GuruCommented:
Glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.