forked from gustavofbreunig/PrintQueueWatchCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintserver.cpp
More file actions
34 lines (27 loc) · 912 Bytes
/
printserver.cpp
File metadata and controls
34 lines (27 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "printserver.h"
PrintServer::PrintServer()
{
}
std::vector<std::wstring> PrintServer::getPrinters()
{
DWORD pcbNeeded, pcbReturned;
//get memory needed
EnumPrinters(PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &pcbNeeded, &pcbReturned);
//fill memory
LPBYTE pPrinters = new BYTE[pcbNeeded];
if (!EnumPrinters(PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL, NULL, 2, pPrinters, pcbNeeded, &pcbNeeded, &pcbReturned))
{
std::string err("EnumPrinters error: " );
err += std::to_string(GetLastError());
throw std::runtime_error(err.c_str());
}
PRINTER_INFO_2* printers = (PRINTER_INFO_2*)pPrinters;
std::vector<std::wstring> buffer;
for (uint32_t i = 0; i < pcbReturned; i++)
{
std::wstring ws(printers[i].pPrinterName);
buffer.push_back(ws);
}
delete[] pPrinters;
return buffer;
}