|
发表于 2014-12-3 08:18:37
|
显示全部楼层
[au3]Func _ENumPrinters($flags = $PRINTER_ENUM_LOCAL)
Local $plist
;stop illegal flags
$flags = BitAND($flags, BitOR($PRINTER_ENUM_CONNECTIONS, $PRINTER_ENUM_LOCAL))
If $flags = 0 Then Return SetError(1, 1, '')
Local $Name = ''
Local $level = 4;uses gets printer_Info_4 which uses registry. Could be done with Printer_Info_2 but can cause long delay
; if printer no longer installed or remote PC not available.
Local $cbBuf = 0;no space allowed but we will be told how much is needed
Local $struct_enum = DllStructCreate("char[" & $cbBuf & "]")
Local $pPrinterEnum = DllStructGetPtr($struct_enum)
Local $pcbNeeded, $pcReturned, $n, $printerdesc, $thisPrinter
$ret = DllCall("winspool.drv", "int", "EnumPrinters", "dword", $flags, "str", $Name, "dword", $level, "ptr", $pPrinterEnum, _
"dword", $cbBuf, "dword*", $pcbNeeded, "dword*", $pcReturned)
If @error Then Return SetError(1, 1, "")
If $ret[6] > $ret[5] Then; if we need more space than we allowed
$struct_enum = DllStructCreate("char[" & $ret[6] & "]")
$pPrinterEnum = DllStructGetPtr($struct_enum)
$ret = DllCall("winspool.drv", "int", "EnumPrinters", "dword", $flags, "str", $Name, "dword", $level, "ptr", $pPrinterEnum, _
"dword", $ret[6], "dword*", $pcbNeeded, "dword*", $pcReturned)
If @error Then Return SetError(2, 2, "")
EndIf
For $n = 0 To $ret[7] - 1;for each $PRINTER_INFO_4 structure in the array of $PRINTER_INFO_4's returned
$ans = DllStructCreate($PRINTER_INFO_4, $pPrinterEnum + $n *12)
$n1 = DllStructCreate("char[256]", DllStructGetData($ans, 1));2 for info_1
$printerdesc = DllStructGetData($n1, 1)
If StringInStr($printerdesc, ',') Then
$thisPrinter = StringLeft($printerdesc, StringInStr($printerdesc, ',') - 1)
Else
$thisPrinter = $printerdesc
EndIf
If $thisPrinter <> '' Then $plist &= $thisPrinter & '|'
Next
If $plist = "" Then Return $plist
Return StringLeft($plist, StringLen($plist) - 1)
EndFunc ;==>_ENumPrinters[/au3] |
|