通过API函数::GetPrinter()来获取打印机的相关信息。
1 HANDLE hPrinter;
2 DWORD dwNeeded=0;
3 PRINTER_INFO_2* pPrinterInfo = NULL;
4 PPRINTER_NOTIFY_INFO pNotify = NULL;
5 ::OpenPrinter((LPTSTR)(LPCTSTR)"打印机名称", &hPrinter, NULL);
6 ::GetPrinter(hPrinter,2,0,0,&dwNeeded);
7 if (dwNeeded <= 0)
8 {
9 LOG("获取打印机信息长度dwNeeded=%d失败,添加打印机消息处理失败", dwNeeded);
10 return 0;
11 }
12 pPrinterInfo = new PRINTER_INFO_2[dwNeeded];
13 if(!::GetPrinter(hPrinter,2,(LPBYTE)pPrinterInfo,dwNeeded,&dwNeeded))
14 {
15 DWORD dError = GetLastError();
16 LOG("获取打印信息失败,错误代码:%d,添加打印机消息处理失败", dError);
17 return 0;
18
19 }
20 ::ClosePrinter(hPrinter);
21 delete []pPrinterInfo;
posted on 2012-05-23 11:00
王海光 阅读(1063)
评论(0) 编辑 收藏 引用 所属分类:
MFC