Vous êtes sur la page 1sur 3

1 /* Copyright (C) 1997-2012, Ghostgum Software Pty Ltd. All rights reserved.

2
3 This file is part of RedMon.
4
5 This software is distributed in the hope that it will be useful,
6 but WITHOUT ANY WARRANTY; without even the implied warranty of
7 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
9 This software is distributed under licence and may not be copied, modified
10 or distributed except as expressly authorised under the terms of the
11 LICENCE.
12
13 */
14
15 /* enum.c */
16 /* List printers, ports, monitors etc. */
17 /* Russell Lang, 1998-01-05 */
18 /* Updated 2005-02-13 to give more details on NT */
19 #include <windows.h>
20 #include <stdio.h>
21
22
23 #ifndef PORT_TYPE_WRITE
24 /* PORT_INFO_2 isn't defined in BC++ 4.5 include files */
25
26 typedef struct _PORT_INFO_2A {
27 LPSTR pPortName;
28 LPSTR pMonitorName;
29 LPSTR pDescription;
30 DWORD fPortType;
31 DWORD Reserved;
32 } PORT_INFO_2A, *PPORT_INFO_2A, *LPPORT_INFO_2A;
33 typedef struct _PORT_INFO_2W {
34 LPWSTR pPortName;
35 LPWSTR pMonitorName;
36 LPWSTR pDescription;
37 DWORD fPortType;
38 DWORD Reserved;
39 } PORT_INFO_2W, *PPORT_INFO_2W, *LPPORT_INFO_2W;
40
41 #ifdef UNICODE
42 typedef PORT_INFO_2W PORT_INFO_2;
43 typedef PPORT_INFO_2W PPORT_INFO_2;
44 typedef LPPORT_INFO_2W LPPORT_INFO_2;
45 #else
46 typedef PORT_INFO_2A PORT_INFO_2;
47 typedef PPORT_INFO_2A PPORT_INFO_2;
48 typedef LPPORT_INFO_2A LPPORT_INFO_2;
49 #endif // UNICODE
50
51 #define PORT_TYPE_WRITE 0x0001
52 #define PORT_TYPE_READ 0x0002
53 #define PORT_TYPE_REDIRECTED 0x0004
54 #define PORT_TYPE_NET_ATTACHED 0x0008
55
56 #endif
57
58
59 char buffer[65536];
60 DWORD needed, returned;
61 int rc;
62 unsigned int i;
63 DRIVER_INFO_2 *dri2;
64 PRINTER_INFO_2 *pri2;
65 PORT_INFO_2 *pi2;
66 MONITOR_INFO_1 *mi;
67 MONITOR_INFO_2 *mi2;
68 DATATYPES_INFO_1 *dti1;
69 PRINTPROCESSOR_INFO_1 *ppi1;
70 BOOL is_winnt = FALSE;
71
72 int main(int argc, char *argv[])
73 {
74 DWORD version = GetVersion();
75 if ((HIWORD(version) & 0x8000)==0)
76 is_winnt = TRUE;
77
78 rc = GetPrintProcessorDirectory (NULL, NULL, 1, buffer,
79 sizeof(buffer), &needed);
80 if (rc)
81 printf("PrintProcessorDirectory = %s\n" , buffer);
82
83 printf("\nPrinters: ");
84 rc = EnumPrinters(PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL,
85 NULL, 2, (LPBYTE)buffer, sizeof(buffer),
86 &needed, &returned);
87 printf("%ld bytes %ld\n", needed, returned);
88 pri2 = (PRINTER_INFO_2 *)buffer;
89 if (rc) {
90 for (i=0; i<returned; i++) {
91 printf("\042%s\042 \042%s\042 \042%s\042 \042%s\042 \042%s\042\n" ,
92 pri2[i].pPrinterName,
93 pri2[i].pPortName,
94 pri2[i].pDriverName,
95 pri2[i].pPrintProcessor,
96 pri2[i].pDatatype
97 );
98 }
99 }
100 else
101 printf("EnumPrinters() failed\n" );
102
103 printf("\nPrinter Drivers: ");
104 rc = EnumPrinterDrivers(NULL, NULL, 2, (LPBYTE)buffer, sizeof(buffer),
105 &needed, &returned);
106 printf("%ld bytes %ld\n", needed, returned);
107 dri2 = (DRIVER_INFO_2 *)buffer;
108 if (rc) {
109 for (i=0; i<returned; i++) {
110 printf("\042%s\042 \042%s\042 \042%s\042 \042%s\042 \042%s\042\n" ,
111 dri2[i].pName,
112 dri2[i].pEnvironment,
113 dri2[i].pDriverPath,
114 dri2[i].pDataFile,
115 dri2[i].pConfigFile
116 );
117 }
118 }
119 else
120 printf("EnumPrinterDrivers() failed\n" );
121
122 printf("\nPorts: (buffer = NULL, length = 0) " );
123 rc = EnumPorts(NULL, 2, NULL, 0, &needed, &returned);
124 printf("%ld bytes %ld\n", needed, returned);
125
126 printf("\nPorts: ");
127 rc = EnumPorts(NULL, 2, (LPBYTE)buffer, sizeof(buffer),
128 &needed, &returned);
129 printf("%ld bytes %ld\n", needed, returned);
130 pi2 = (PORT_INFO_2 *)buffer;
131 if (rc) {
132 for (i=0; i<returned; i++) {
133 printf("\042%s\042 \042%s\042 \042%s\042 %d\n" ,
134 pi2[i].pPortName,
135 pi2[i].pMonitorName,
136 pi2[i].pDescription,
137 pi2[i].fPortType
138 );
139 }
140 }
141 else
142 printf("EnumPorts() failed\n" );
143
144 printf("\nMonitors: ");
145 rc = EnumMonitors(NULL, is_winnt ? 2 : 1, (LPBYTE)buffer, sizeof(buffer),
146 &needed, &returned);
147 printf("%ld bytes %ld\n", needed, returned);
148 mi = (MONITOR_INFO_1 *)buffer;
149 mi2 = (MONITOR_INFO_2 *)buffer;
150 if (rc) {
151 for (i=0; i<returned; i++) {
152 if (is_winnt)
153 printf("%d: \042%s\042 \042%s\042 \042%s\042\n" ,
154 i, mi2[i].pName, mi2[i].pEnvironment, mi2[i].pDLLName);
155 else
156 printf("%d: \042%s\042 \n", i, mi[i].pName);
157 }
158 }
159 else
160 printf("EnumMonitors() failed\n" );
161
162 printf("\nPrintProcessors: ");
163 rc = EnumPrintProcessors(NULL, NULL, 1,
164 (LPBYTE)buffer, sizeof(buffer),
165 &needed, &returned);
166 printf("%ld bytes %ld\n", needed, returned);
167 ppi1 = (PRINTPROCESSOR_INFO_1 *)buffer;
168 if (rc) {
169 for (i=0; i<returned; i++) {
170 printf("\042%s\042\n", ppi1[i].pName);
171 }
172 }
173 else
174 printf("EnumPrintProcessor() failed\n" );
175
176 printf("\nPrintProcessorDatatypes (WinPrint): " );
177 rc = EnumPrintProcessorDatatypes (NULL, "WinPrint", 1,
178 (LPBYTE)buffer, sizeof(buffer),
179 &needed, &returned);
180 printf("%ld bytes %ld\n", needed, returned);
181 dti1 = (DATATYPES_INFO_1 *)buffer;
182 if (rc) {
183 for (i=0; i<returned; i++) {
184 printf("\042%s\042\n", dti1[i].pName);
185 }
186 }
187 else
188 printf("EnumPrintProcessorDatatypes() failed\n" );
189
190
191
192 return 0;
193 }
194

Vous aimerez peut-être aussi