VC枚举打印机驱动(EnumPrinterDrivers DRIVER_INFO_1)
1 DRIVER_INFO_1 *pLevel1 = NULL;
2 DWORD dwNeeded = 0,
3 dwReceived = 0,
4 dwError = 0;
5 int nRet = 0;
6
7 nRet = EnumPrinterDrivers(NULL, // local machine
8 NULL, // current environment
9 1, // level 1, whatever that means
10 (LPBYTE) pLevel1,
11 0,
12 &dwNeeded,
13 &dwReceived);
14
15 if (0 == nRet)
16 {
17 dwError = GetLastError();
18
19 }
20
21 pLevel1 = (DRIVER_INFO_1 *) calloc(1, dwNeeded);
22
23 nRet = EnumPrinterDrivers(NULL, // local machine
24 NULL, // current environment
25 1, // level 1, whatever that means
26 (LPBYTE) pLevel1,
27 dwNeeded,
28 &dwNeeded,
29 &dwReceived);
30
31 for (int nCount = 0; nCount < (int) dwReceived; nCount ++)
32 {
33 printf("Name: %s\r\n", pLevel1[nCount].pName);
34 }
代码摘自 http://visual-c.itags.org/visual-c-c++/102968/