win32-api
Version:
FFI definitions of windows win32 api for node-ffi
24 lines • 856 B
JavaScript
import { load } from '../../lib/winspool/index.js';
const funcName = 'GetPrinterW';
// type RetType = ReturnType<FnType>
// type ParamType = Parameters<FnType>
/**
* @link https://learn.microsoft.com/zh-cn/windows/win32/printdocs/getprinter
*/
export async function GetPrinter(options) {
const { hPrinter, Level, maxLength = 1024 } = options;
const lib = load([funcName]);
const pPrinter = {};
const cbBuf = (maxLength + 1) * 2;
const pcbNeeded = Buffer.alloc(8);
const ret = await lib.GetPrinterW_Async(hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
const pcb = pcbNeeded.readUInt32LE();
if (!ret) {
if (pcb > maxLength) {
throw new Error(`maxLength is too small, increase to value grater than ${pcb}`);
}
return null;
}
return pPrinter;
}
//# sourceMappingURL=GetPrinter.js.map