Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » About Get Printer list from windows
About Get Printer list from windows [message #61859] Thu, 20 November 2025 00:40
fzx374cn is currently offline  fzx374cn
Messages: 4
Registered: August 2025
Junior Member
#include <CtrlLib/CtrlLib.h>
#include <windows.h>
#include <winspool.h>

using namespace Upp;

Vector<String> EnumeratePrinters() {
Vector<String> printers;
DWORD needed = 0;
DWORD returned = 0;


// 第一次调用获取所 需缓冲区大小
if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, NULL, 0, &needed, &returned)) {
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
return printers;
}
}

// 分配缓冲区
Buffer<BYTE> buffer(needed);


// 第二次调用获取打印机信息
if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, buffer, needed, &needed, &returned)) {
PRINTER_INFO_4* printerInfo = (PRINTER_INFO_4*)buffer;

for (DWORD i = 0; i < returned; i++) {
printers.Add(printerInfo[i].pPrinterName);
}
}

return printers;
}

GUI_APP_MAIN {
Vector<String> printers = EnumeratePrinters();

for (int i = 0; i < printers.GetCount(); i++) {
Cout() << "打印机 " << i << ": " << printers[i] << "\n";
}
}
//Why can't run?
Previous Topic: How to Retrieve Printer List from Windows System?
Next Topic: Add compilable testcases for nontrivial problems!
Goto Forum:
  


Current Time: Thu Nov 20 01:59:39 CET 2025

Total time taken to generate the page: 0.10600 seconds