Jump to content

help Printer papernames and papersizes


Recommended Posts

AM trying to convert this code that retrieves printer papernames ans sizes from vb6 to autoit

Dim paperNumbers()      As Integer, paperSizes() As POINTAPI

lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, DC_PAPERNAMES, ByVal vbNullString, 0)
    ReDim numPaper(1 To lPaperCount)
    sPaperNamesList = String(64 * lPaperCount, 0)
    ' Get paper names
    lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, DC_PAPERNAMES, ByVal sPaperNamesList, 0)
    ' Get matching paper numbers
    ReDim paperNumbers(1 To lPaperCount)
    lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, DC_PAPERS, paperNumbers(1), 0)
    ReDim paperSizes(1 To lPaperCount)
    lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, DC_PAPERSIZE, paperSizes(1), 0)
    For lCounter = 1 To lPaperCount
        sNextString = Mid(sPaperNamesList, 64 * (lCounter - 1) + 1, 64)
        sNextString = Left(sNextString, InStr(1, sNextString, Chr(0)) - 1)
        List2.AddItem paperNumbers(lCounter) & vbTab _
            & Format(paperSizes(lCounter).x / 254, "0.00") & " x " _
            & Format(paperSizes(lCounter).y / 254, "0.00") _
            & " inch" & vbTab & sNextString
    Next lCounter

The auto it version

Dim $numPaper[$lPaperCount[0]]
 $lPaperCount = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERSIZE, "str", DllStructGetPtr($paperSizes), "ptr", 0)
    
    Dim $OutPut
    For $lCounter = 1 To $lPaperCount-1
        $sNextString = StringMid($sPaperNamesList, 64 * ($lCounter - 1) + 1, 64)
        $sNextString = stringLeft($sNextString, StringInStr($sNextString, Chr(0),1,1,1) - 1)
        $OutPut &= $paperNumbers($lCounter) & @Tab 
        $OutPut &= StringFormat("%10.2f",$paperSizes($lCounter).x / 254) & " x "
        $OutPut &= StringFormat("%10.2f",$paperSizes($lCounter).y / 254)  & " inch" & @tab & $sNextString @CRLF
    Next

I don't het anything in my output.

$paperSizes is suppose to be and array of points (x,y) retrieved from the dllcall

Edited by oghenez
Link to comment
Share on other sites

#include <Array.au3>

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer",Default,48)
For $objPrinter In $colInstalledPrinters
    $arr = $objPrinter.PrinterPaperNames
    _ArrayDisplay($arr, $objPrinter.Name)
Next

Check out this too: http://stackoverflow.com/questions/5549476/dllcall-autoit-partially-getting-results

:)

Link to comment
Share on other sites

If your printers are network printers managed by a spool server you can get a lot of information about the print queues using my AD UDF, function _AD_ListPrintQueues and _AD_GetObjectProperties.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

#include <Array.au3>

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer",Default,48)
For $objPrinter In $colInstalledPrinters
    $arr = $objPrinter.PrinterPaperNames
    _ArrayDisplay($arr, $objPrinter.Name)
Next

Check out this too: http://stackoverflow.com/questions/5549476/dllcall-autoit-partially-getting-results

:)

I tried this, but it dosen't return the actual paper sizes. it returns series of 1s. the paper sizes is suppose to be Xmm x Ymm

#include <Array.au3>

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer",Default,48)
For $objPrinter In $colInstalledPrinters
    $arr = $objPrinter.PaperSizesSupported 
    _ArrayDisplay($arr, $objPrinter.Name)
Next
Link to comment
Share on other sites

help me get the names & sizes here, but am left with the papernumbers, please help me with the struct, thats where i get confused

in vb6 i can do this

Dim paperNumbers()  As Integer

and pass it to the api like this

' Get paper names
    lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, DC_PAPERNAMES, ByVal sPaperNamesList, 0)
    ' Get matching paper numbers
    ReDim paperNumbers(1 To lPaperCount)
    lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, DC_PAPERS, paperNumbers(1), 0)

in autoit i did this

but get the result posted at the buttom of that post

Edited by TheCurrent
Link to comment
Share on other sites

I tried this, but it dosen't return the actual paper sizes. it returns series of 1s. the paper sizes is suppose to be Xmm x Ymm

#include <Array.au3>

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer",Default,48)
For $objPrinter In $colInstalledPrinters
    $arr = $objPrinter.PaperSizesSupported 
    _ArrayDisplay($arr, $objPrinter.Name)
Next

Yes, you need to translate the numbers yourself which is quite a simple job. Paper sizes is described on the page I linked you at: http://msdn.microsoft.com/en-us/library/aa394363(v=vs.85).aspx

For example I see my printer supports 8 which is A3. I know that it is 297x420 so I would make this code:

Switch $paperSizeType
   Case 8
      Return "A3 (297mm x 420mm)"
EndSwitch

The solution is not as good as the one MrMitchell gave you in the other thread, but when you say you "have been doing this for four days now by myself" doing this would mean that you were done 3 days ago.

Edited by Manadar
Link to comment
Share on other sites

what i meant by "have been doing this for four days now by myself" is that i have been trying to do it myself without success

By the way, how do i pass an array or int to dllcall and retrieve the result?

i tried this

$result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "str", Chr(0), "long", 0)
;Create all the structures to retrieve the necessary values
$NumberStruct = ""
For $i = 1 To $result[0]
$NumberStruct &="int;"
Next
$NumberStruct = StringTrimRight($NumberStruct, 1)
$pNumberStruct = DllStructCreate($NumberStruct)
;Get paper Numbers
$result1 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "ptr", DllStructGetPtr($pNumberStruct), "long", 0)
For $i = 1 To $result[0]
ConsoleWrite(DllStructGetData($pNumberStruct, $i) & @CRLF)
Next

i got this

196609
327684
524295
4325385
11534511
11665585
11796659
11927733
12058807
12189881
12320955
12452029
12583103
12714177
12845251
12976325
13107399
13238473
13369547
2147418317
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

which is not complete or somthing. what am i doing wrong?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...