网站建议:179001057@qq.com

枚举本地所有的打印机

技术2022-05-11  0

#include <winspool.h> #include <commdlg.h> //函数体 DWORD dwFlags = PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL; LPPRINTER_INFO_2 pPrinters; DWORD cbPrinters; DWORD cReturned, i; char buf[256]; EnumPrinters (dwFlags, NULL, 2, NULL, 0, &cbPrinters, &cReturned); if (!(pPrinters = (LPPRINTER_INFO_2) LocalAlloc (LPTR, cbPrinters + 4))) { ::MessageBox (NULL, "error", "error", MB_OK | MB_ICONEXCLAMATION); } if (!EnumPrinters (dwFlags, NULL, 2, (LPBYTE) pPrinters, cbPrinters, &cbPrinters, &cReturned)) { ::MessageBox (NULL, "error", "error", MB_OK | MB_ICONEXCLAMATION); } if (cReturned > 0) { for (i = 0; i < cReturned; i++) { // // for each printer in the PRINTER_INFO_2 array: build a string that // looks like "DEVICE_NAME;PORT;DRIVER_NAME" // strcpy (buf, (pPrinters + i)->pPrinterName); strcat (buf, ";"); strcat (buf, (pPrinters + i)->pPortName); strcat (buf, ";"); strcat (buf, (pPrinters + i)->pDriverName); } } else ::MessageBox (NULL, "No printers listed", "PRINTER.EXE", MB_OK);  


最新回复(0)