Jump to content

pass array of pointapi in autoit, how?


Recommended Posts

in vb6, i can do this

Private Type POINTAPI
    x As Long
    y As Long
End Type

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

this is what i tried in autoit

$struct = DllStructCreate("long x[$result[0]];long y[$result[0]]")

but am not getting the desired result am expecting making this dll call

$result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)

Can anyone point me in the right direction?

Link to comment
Share on other sites

  • Moderators

$struct = DllStructCreate("long x;long y")

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

@smoke thanks fro responding,

this is my autoit code that's not working, what am i doing wrong?

#include <Debug.au3>
#include <String.au3>
#include <Array.au3>

Const $DC_PAPERNAMES = 16
Const $DC_PAPERS = 2
Const $DC_PAPERSIZE = 3
Dim $BinNameList
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
    $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0)
    $s_struct = ""
_DebugSetup ($s_struct)
    ;here am suppose to creat an array or points (x,y) of size $result[0]
    $struct = DllStructCreate("long x;long y")
;pass array of structure i created above, the dllcall is suppose to fill the array of points with values
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "str", DllStructGetPtr($struct), "long", 0)
    _DebugOut ( $objPrinter.Name) 
    For $i = 0 To $result[0]-1
            ;now i don't get anything here, am suppose to get the array of returned values from autoit
        _DebugOut (DllStructGetData($struct, 1) & " x " & DllStructGetData($struct, 2)) 
    Next
    $struct = 0
Next
Edited by TheCurrent
Link to comment
Share on other sites

$struct = DllStructCreate("long x;long y")

after passing this structure, can you tell me how to get the values from the dll struct?

see what i did

$s_struct = _StringRepeat("Int;",$result[0])
    $struct = DllStructCreate($s_struct)
; this call is suppose to return an array of integers, 
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "ptr", DllStructGetPtr($struct), "long", 0)
    For $i = 1 To $result[0]
        _DebugOut(DllStructGetData($struct, $i))
        
    Next
Edited by TheCurrent
Link to comment
Share on other sites

after passing this structure, can you tell me how to get the values from the dll struct?

see what i did

[autoit]

$s_struct = _StringRepeat("Int;",$result[0])

$struct = DllStructCreate($s_struct)

; this call is suppose to return an array of integers,

$result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "ptr", DllStructGetPtr($struct), "long", 0)

For $i = 1 To $result[0]

_DebugOut(DllStructGetData($struct, $i))

Next[ /autoit]

The values you're getting as a result of the code above should correspond to this table.

If you want the names of the paper sizes (i.e. Letter, Legal, A4,...) then you'll need to:

  • Add a const...

    Const $DC_PAPERNAMES = 16

  • Change your "Word;" in $s_struct to "Char[64];"
  • Then change $DC_PAPERS in $result2 to $DC_PAPERNAMES
What I can't get, and what I think you're trying to do, is use $DC_PAPERSIZE and get the actual dimensions of each paper type. Is that right, or no?
Link to comment
Share on other sites

Thanks for responding, yes i already did that, and what am trying to do is get papernumbers (each paper has a number associated with it)papersizes ( this size is returned as an array or int x & y in millimeter).

this is the attempt i made

for the papernumbers

$result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "str", Chr(0), "long", 0)
    $s_struct = ""
    _DebugSetup ($s_struct)
$s_struct = _StringRepeat("Int;",$result[0])
    $struct = DllStructCreate($s_struct)
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "ptr", DllStructGetPtr($struct), "long", 0)
    For $i = 1 To $result[0]
        _DebugOut(DllStructGetData($struct, $i))
        
    Next
    ;_DebugOut(_ArrayToString($result2, ", "))
    $struct = 0
Edited by TheCurrent
Link to comment
Share on other sites

This what I have...

Const $DC_PAPERS = 2
Const $DC_PAPERSIZE = 3
Const $DC_PAPERNAMES = 16

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")

For $objPrinter In $colInstalledPrinters
    $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0)

    $s_struct = ""
    $s_struct2 = ""

    For $i = 1 To $result[0]
        $s_struct = $s_struct & "char[64];"
    Next

    For $i = 1 To $result[0]
        $s_struct2 &= "long x;long y;"
    Next

    $s_struct = StringTrimRight($s_struct, 1)
    $s_struct2 = StringTrimRight($s_struct2, 1)
    $j = 1

    $struct = DllStructCreate($s_struct)
    $pointStruct = DllStructCreate($s_struct2)

    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
    $result3 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERSIZE, "ptr", DllStructGetPtr($pointStruct), "long", 0)

    ConsoleWrite($objPrinter.Name & " on Port: " & $objPrinter.PortName & @CRLF)
    For $i = 1 To $result[0]
        ConsoleWrite(DllStructGetData($struct, $i) & " (" & DllStructGetData($pointStruct, $j) & "mm x " & DllStructGetData($pointStruct, $j + 1) & "mm)" & @CRLF)
        $j += 2
    Next

    $struct = 0
    $pointStruct = 0
Next

Example of output for just 1 printer:

\\server\printername on Port: 10.38.1.25:10.38.1.25

Letter (2159mm x 2794mm)

Legal (2159mm x 3556mm)

Executive (1841mm x 2667mm)

A4 (2099mm x 2969mm)

A5 (1479mm x 2099mm)

JIS B5 (1819mm x 2569mm)

US Folio (2159mm x 3302mm)

No.10 Env. (1047mm x 2413mm)

DL Env. (1099mm x 2199mm)

C5 Env. (1619mm x 2289mm)

C6 Env. (1139mm x 1620mm)

ISO B5 (1759mm x 2499mm)

Monarch Env. (983mm x 1905mm)

A6 (1049mm x 1479mm)

Oficio (2159mm x 3429mm)

Tabloid (2794mm x 4318mm)

A3 (2971mm x 4191mm)

B4 (2565mm x 3632mm)

Custom Size (2159mm x 2794mm)

Edited by MrMitchell
Link to comment
Share on other sites

:) thank you so much MrMitchell :)

to retrieve the paper numbers, i tried this

#include <Debug.au3>
#include <String.au3>
#include <Array.au3>
Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Const $DC_PAPERNAMES = 16
Const $DC_PAPERS = 2
Const $DC_PAPERSIZE = 3

Dim $BinNameList
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer  Where Name = 'Adobe PDF'")
For $objPrinter In $colInstalledPrinters
    $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "str", Chr(0), "long", 0)
    $s_struct = ""
    _DebugSetup ($s_struct)
   $s_struct =  _StringRepeat("Int;",$result[0]-1)
    $struct = DllStructCreate($s_struct)
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "ptr", DllStructGetPtr($struct), "long", 0)
    For $i = 1 To $result[0]
        _DebugOut(DllStructGetData($struct, $i))
        
    Next
    ;_DebugOut(_ArrayToString($result2, ", "))
    $struct = 0
Next

this is what i get

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

but it didn't work

Link to comment
Share on other sites

Just FYI I didn't realize what I put on my previous post would work until I saw post. So Kudos to Siao, even though it appears he hasn't been on here for some time...

Anyway, for numbers this works for me:

#include <String.au3>

Const $DC_PAPERS = 2
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
    $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0)
    $s_struct = _StringRepeat("Word;",$result[0])
    $struct = DllStructCreate($s_struct)
    ; this call is suppose to return an array of integers,
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "ptr", DllStructGetPtr($struct), "long", 0)
    ConsoleWrite($objPrinter.Name & @CRLF)
    For $i = 1 To $result[0]
        ConsoleWrite(DllStructGetData($struct, $i) & @CRLF)
    Next
Next

Any results above 118 appear to be custom paper sizes.

Link to comment
Share on other sites

thank you so much, you are very great

Apart from asking in the forums & the autoit help chm, can you give me links,rferences, tutorial etc where i can learn making these structures

Edited by TheCurrent
Link to comment
Share on other sites

thank you so much, you are very great

No problem!

Quick question...a little while back you told me you didn't want to use WMI because it was slow, yet you're using it in this script. Were you going to remove the WMI stuff in your current script and use DLL instead? Just wondering that's all. This is my first time ever dealing with DLLs, so now you've got me interested in working more with it lol

Link to comment
Share on other sites

Apart from asking in the forums & the autoit help chm, can you give me links,rferences, tutorial etc where i can learn making these structures

Well, like you, I'm very new to it too. I started with AutoIt Help File, then I found a short PDF doc with a few exercises (it was in a forum post, I'll post a link if I can find it), then for more I just started searching forum posts. It was enough to get a good start... the only other place I can suggest is MSDN, but that's just the reference for the DLL, what functions they contain and how to use them.

Edit:

Edited by MrMitchell
Link to comment
Share on other sites

FYI: On the german AutoIt forum I found this program H2AU3 (still beta but for me it's working fine) to translate C-Constants, function declarations and structure definitions into AutoIt-Code:

Check this screenshots.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

if i have to remove WMI, then i'll have to call EnumPrinters

please let me be your student, you can open a new thread "API Structure Playground" you teach one, and give assignment, it will be fun, and i'll be glad to be your student.

this is the structure, how do you convert this to autoit,

Found here

BOOL EnumPrinters(
  __in   DWORD Flags,
  __in   LPTSTR Name,
  __in   DWORD Level,
  __out  LPBYTE pPrinterEnum,
  __in   DWORD cbBuf,
  __out  LPDWORD pcbNeeded,
  __out  LPDWORD pcReturned
);

in vb6 to get the printer names, instead of using WMI, this is how i use it

'Example #: 1
Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long

Dim longbuffer() As Long ' resizable array receives information from the function
Dim printinfo() As PRINTER_INFO_1 ' values inside longbuffer() will be put into here
Dim numbytes As Long ' size in bytes of longbuffer()
Dim numneeded As Long ' receives number of bytes necessary if longbuffer() is too small
Dim numprinters As Long ' receives number of printers found
Dim c As Integer, retval As Long ' counter variable & return value

' Get information about the local printers
numbytes = 3076 ' should be sufficiently big, but it may not be
ReDim longbuffer(0 To numbytes / 4) As Long ' resize array -- note how 1 Long = 4 bytes
retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 1, longbuffer(0), numbytes, numneeded, numprinters)
If retval = 0 Then ' try enlarging longbuffer() to receive all necessary information
numbytes = numneeded
ReDim longbuffer(0 To numbytes / 4) As Long ' make it large enough
retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 1, longbuffer(0), numbytes, numneeded, numprinters)
If retval = 0 ' failed again!
Debug.Print "Could not successfully enumerate the printes."
End ' abort program
End If
End If

' Convert longbuffer() data into printinfo()
ReDim printinfo(0 To numprinters - 1) As PRINTER_INFO_1 ' room for each printer
For c = 0 To numprinters - 1 ' loop, putting each set of information into each element
' longbuffer(4 * c) = .flags, longbuffer(4 * c + 1) = .pDescription, etc.
' For each string, the string is first buffered to provide enough room, and then the string is copied.
printinfo(c).flags = longbuffer(4 * c)
printinfo(c).pDescription = Space(lstrlen(longbuffer(4 * c + 1)))
retval = lstrcpy(printinfo(c).pDescription, longbuffer(4 * c + 1))
printinfo(c).pName = Space(lstrlen(longbuffer(4 * c + 2)))
retval = lstrcpy(printinfo(c).pName, longbuffer(4 * c + 2))
printinfo(c).pComment = Space(lstrlen(longbuffer(4 * c + 3)))
retval = lstrcpy(printinfo(c).pComment, longbuffer(4 * c + 3))
Next 

' Display name of each printer
For c = 0 To numprinters - 1
Debug.Print "Name of printer"; c + 1; " is: "; printinfo(c).pName
Next
Edited by TheCurrent
Link to comment
Share on other sites

FYI: On the german AutoIt forum I found this program H2AU3 (still beta but for me it's working fine) to translate C-Constants, function declarations and structure definitions into AutoIt-Code:

Check this screenshots.

Sweet! That sure makes things a little easier huh...even if you have to go back and make a few adjustments, but at least the bulk of it gets done.

Link to comment
Share on other sites

this is the structure, how do you convert this to autoit,

Found here

BOOL EnumPrinters(
  __in   DWORD Flags,
  __in   LPTSTR Name,
  __in   DWORD Level,
  __out  LPBYTE pPrinterEnum,
  __in   DWORD cbBuf,
  __out  LPDWORD pcbNeeded,
  __out  LPDWORD pcReturned
);
I will give H2AU3 a try tomorrow and post the results.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

i will be glad to try this tool too, and maybe improve it

In you can find a link to the german forum and the thread discussing this script plus a screenshot.

As everything is written in german (thread and script) do you need a bit of translation?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

The site seems to be down at the moment.

I will try it again a bit later.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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...