Dllcall autoit 部分获取结果

发布于 2024-10-30 05:26:07 字数 1222 浏览 0 评论 0原文

我在 autoit 中遇到以下代码问题:

它应该列出我的系统中可用的所有打印机以及每台打印机支持的当前纸张名称。

但我只得到打印机名称和一系列“0”,这应该是纸张名称

#include <Debug.au3>
#include <String.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")
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)
    $s_struct=_StringRepeat("0", $result[0]*64)
    ;$s_struct = StringTrimRight($s_struct, 1)
    $struct = DllStructCreate($s_struct)
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
    _DebugOut ( $objPrinter.Name) 
    For $i = 0 To $result[0]-1
        _DebugOut (DllStructGetData($struct, $i)) 
    Next
    $struct = 0
Next

I am having problem with the following code in autoit.

it is suppose to list all printers available in my system and the curresponding papernames supported by each printer.

but am getting only the printer names ans series of '0s' which is suppose to be the papernames

#include <Debug.au3>
#include <String.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")
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)
    $s_struct=_StringRepeat("0", $result[0]*64)
    ;$s_struct = StringTrimRight($s_struct, 1)
    $struct = DllStructCreate($s_struct)
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
    _DebugOut ( $objPrinter.Name) 
    For $i = 0 To $result[0]-1
        _DebugOut (DllStructGetData($struct, $i)) 
    Next
    $struct = 0
Next

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素食主义者 2024-11-06 05:26:07

请查看:http://msdn.microsoft。 com/en-us/library/aa394363(v=vs.85).aspx

仅使用 WMI 的示例:

#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

或者尝试打印实际的纸张名称(在 SciTE 中运行,以便您可以看到 ConsoleWrite 的输出) :

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

Check this out: http://msdn.microsoft.com/en-us/library/aa394363(v=vs.85).aspx

Example that uses just WMI:

#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

Or try this which prints the actual paper names (run in SciTE so you can see the output from ConsoleWrite):

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文