UNPKG

win32-api

Version:

FFI definitions of windows win32 api for node-ffi

35 lines 1.56 kB
import assert from 'node:assert'; // must use ffi from 'win32-def' import { ffi } from 'win32-def'; import { PRINTER_INFO_X_Factory, getPRINTER_INFO_X_Ptr, } from 'win32-def/struct'; import { load } from '../../lib/winspool/index.js'; const funcName = 'EnumPrintersW'; /** * Enumerates available printers, print servers, domains, or print providers. * @link https://learn.microsoft.com/en-us/windows/win32/printdocs/enumprinters * * 枚举可用的打印机、打印服务器、域或打印提供程序 * @link https://learn.microsoft.com/zh-cn/windows/win32/printdocs/enumprinters */ export async function EnumPrinters(options) { const level = options.Level; const lib = load([funcName]); const name = ''; // assert(level >= 1 && level <= 5, 'level must be >= 1 and <= 5') const cbBuf = options.cbBuf ?? 4096; assert(cbBuf > 2, 'cbBuf must be > 2'); const buf = Buffer.alloc(cbBuf); const pcbNeeded = Buffer.alloc(4); const pcReturned = Buffer.alloc(4); const ret = await lib.EnumPrintersW_Async(options.Flags, name, level, buf, cbBuf, pcbNeeded, pcReturned); assert(ret, 'EnumPrintersW() failed'); PRINTER_INFO_X_Factory(level); const count = pcReturned.readUInt32LE(); // const pcb = pcbNeeded.readUInt32LE() const ptr = getPRINTER_INFO_X_Ptr(level); const key = ptr.replace(/\s*\*/u, ''); // 'PRINTER_INFO_1' | 'PRINTER_INFO_2' const decodeType = `${key}[${count}]`; const infoArr = ffi.decode(buf, decodeType); return infoArr; } //# sourceMappingURL=EnumPrinters.js.map