Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

help Printer papernames and papersizes


  • Please log in to reply
6 replies to this topic

#1 TheCurrent

TheCurrent

    Wayfarer

  • Active Members
  • Pip
  • 70 posts

Posted 04 April 2011 - 04:11 PM

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, 04 April 2011 - 04:13 PM.








#2 Manadar

Manadar

         

  • MVPs
  • 10,878 posts

Posted 07 April 2011 - 06:47 AM

#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

:)

#3 water

water

    ?

  • MVPs
  • 15,566 posts

Posted 07 April 2011 - 07:27 AM

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, 07 April 2011 - 07:27 AM.

UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#4 TheCurrent

TheCurrent

    Wayfarer

  • Active Members
  • Pip
  • 70 posts

Posted 07 April 2011 - 08:11 AM

#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


#5 TheCurrent

TheCurrent

    Wayfarer

  • Active Members
  • Pip
  • 70 posts

Posted 07 April 2011 - 08:35 AM

MrMitchell 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
http://www.autoitscript.com/forum/topic/127287-pass-array-of-pointapi-in-autoit-how/page__view__findpost__p__883689

but get the result posted at the buttom of that post

Edited by TheCurrent, 07 April 2011 - 08:38 AM.


#6 Manadar

Manadar

         

  • MVPs
  • 10,878 posts

Posted 07 April 2011 - 08:40 AM

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, 07 April 2011 - 08:40 AM.


#7 TheCurrent

TheCurrent

    Wayfarer

  • Active Members
  • Pip
  • 70 posts

Posted 07 April 2011 - 09:16 AM

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

Plain Text         
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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users