Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include<vector>
- std::vector<char*> query_printers(){
- DWORD dwReturned;
- DWORD dwNeeded;
- PRINTER_INFO_4 *pInfo;
- char szPrinterName[255];
- unsigned long lPrinterNameLength;
- GetDefaultPrinter(szPrinterName, &lPrinterNameLength);
- auto fnReturn = EnumPrinters(
- PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
- szPrinterName,
- 1L, // printer info level
- (LPBYTE)NULL,
- 0L,
- &dwNeeded,
- &dwReturned);
- if (dwNeeded > 0)
- {
- pInfo = (PRINTER_INFO_4 *)HeapAlloc(
- GetProcessHeap(), 0L, dwNeeded);
- }
- if (NULL != pInfo)
- {
- dwReturned = 0;
- fnReturn = EnumPrinters(
- PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
- NULL,
- 1L, // printer info level
- (LPBYTE)pInfo,
- dwNeeded,
- &dwNeeded,
- &dwReturned);
- }
- std::vector<char*> names;
- if (fnReturn)
- {
- std::string cached_name;
- for (auto i = 0; i < dwReturned; i++)
- {
- cached_name = pInfo[i].pPrinterName;
- if (cached_name.find("NULL") != std::string::npos ||
- cached_name.empty())
- continue;
- names.push_back(pInfo[i].pPrinterName);
- }
- }
- return names;
- }
- std::vector<HDC> get_printers_dc(){
- auto printers = query_printers();
- std::vector<HDC> device_contexts;
- for (auto& printer : printers)
- {
- device_contexts.push_back(CreateDC("WINSPOOL", printer, NULL, NULL));
- }
- return device_contexts;
- }
- int main(){
- auto captured = get_printers_dc();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement