Dllcall autoit 部分获取结果
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请查看:http://msdn.microsoft。 com/en-us/library/aa394363(v=vs.85).aspx
仅使用 WMI 的示例:
或者尝试打印实际的纸张名称(在 SciTE 中运行,以便您可以看到 ConsoleWrite 的输出) :
Check this out: http://msdn.microsoft.com/en-us/library/aa394363(v=vs.85).aspx
Example that uses just WMI:
Or try this which prints the actual paper names (run in SciTE so you can see the output from ConsoleWrite):