/
Winspool.java
1381 lines (1293 loc) · 60.5 KB
/
Winspool.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
*
* The contents of this file is dual-licensed under 2
* alternative Open Source/Free licenses: LGPL 2.1 or later and
* Apache License 2.0. (starting with JNA version 4.0.0).
*
* You can freely decide which license you want to apply to
* the project.
*
* You may obtain a copy of the LGPL License at:
*
* http://www.gnu.org/licenses/licenses.html
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "LGPL2.1".
*
* You may obtain a copy of the Apache License at:
*
* http://www.apache.org/licenses/
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "AL2.0".
*/
package com.sun.jna.platform.win32;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.Structure.FieldOrder;
import com.sun.jna.Union;
import com.sun.jna.platform.win32.WinBase.SYSTEMTIME;
import com.sun.jna.platform.win32.WinDef.DWORD;
import com.sun.jna.platform.win32.WinDef.DWORDByReference;
import com.sun.jna.platform.win32.WinDef.INT_PTR;
import com.sun.jna.platform.win32.WinDef.LPVOID;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
/**
* Ported from Winspool.h. Windows SDK 6.0a
*
* @author dblock[at]dblock.org
*/
public interface Winspool extends StdCallLibrary {
Winspool INSTANCE = Native.load("Winspool.drv", Winspool.class, W32APIOptions.DEFAULT_OPTIONS);
public static final int CCHDEVICENAME = 32;
public static final int PRINTER_STATUS_PAUSED = 0x00000001;
public static final int PRINTER_STATUS_ERROR = 0x00000002;
public static final int PRINTER_STATUS_PENDING_DELETION = 0x00000004;
public static final int PRINTER_STATUS_PAPER_JAM = 0x00000008;
public static final int PRINTER_STATUS_PAPER_OUT = 0x00000010;
public static final int PRINTER_STATUS_MANUAL_FEED = 0x00000020;
public static final int PRINTER_STATUS_PAPER_PROBLEM = 0x00000040;
public static final int PRINTER_STATUS_OFFLINE = 0x00000080;
public static final int PRINTER_STATUS_IO_ACTIVE = 0x00000100;
public static final int PRINTER_STATUS_BUSY = 0x00000200;
public static final int PRINTER_STATUS_PRINTING = 0x00000400;
public static final int PRINTER_STATUS_OUTPUT_BIN_FULL = 0x00000800;
public static final int PRINTER_STATUS_NOT_AVAILABLE = 0x00001000;
public static final int PRINTER_STATUS_WAITING = 0x00002000;
public static final int PRINTER_STATUS_PROCESSING = 0x00004000;
public static final int PRINTER_STATUS_INITIALIZING = 0x00008000;
public static final int PRINTER_STATUS_WARMING_UP = 0x00010000;
public static final int PRINTER_STATUS_TONER_LOW = 0x00020000;
public static final int PRINTER_STATUS_NO_TONER = 0x00040000;
public static final int PRINTER_STATUS_PAGE_PUNT = 0x00080000;
public static final int PRINTER_STATUS_USER_INTERVENTION = 0x00100000;
public static final int PRINTER_STATUS_OUT_OF_MEMORY = 0x00200000;
public static final int PRINTER_STATUS_DOOR_OPEN = 0x00400000;
public static final int PRINTER_STATUS_SERVER_UNKNOWN = 0x00800000;
public static final int PRINTER_STATUS_POWER_SAVE = 0x01000000;
public static final int PRINTER_ATTRIBUTE_QUEUED = 0x00000001;
public static final int PRINTER_ATTRIBUTE_DIRECT = 0x00000002;
public static final int PRINTER_ATTRIBUTE_DEFAULT = 0x00000004;
public static final int PRINTER_ATTRIBUTE_SHARED = 0x00000008;
public static final int PRINTER_ATTRIBUTE_NETWORK = 0x00000010;
public static final int PRINTER_ATTRIBUTE_HIDDEN = 0x00000020;
public static final int PRINTER_ATTRIBUTE_LOCAL = 0x00000040;
public static final int PRINTER_ATTRIBUTE_ENABLE_DEVQ = 0x00000080;
public static final int PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS = 0x00000100;
public static final int PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST = 0x00000200;
public static final int PRINTER_ATTRIBUTE_WORK_OFFLINE = 0x00000400;
public static final int PRINTER_ATTRIBUTE_ENABLE_BIDI = 0x00000800;
public static final int PRINTER_ATTRIBUTE_RAW_ONLY = 0x00001000;
public static final int PRINTER_ATTRIBUTE_PUBLISHED = 0x00002000;
public static final int PRINTER_ATTRIBUTE_FAX = 0x00004000;
public static final int PRINTER_ATTRIBUTE_TS = 0x00008000;
public static final int PRINTER_ATTRIBUTE_PUSHED_USER = 0x00020000;
public static final int PRINTER_ATTRIBUTE_PUSHED_MACHINE = 0x00040000;
public static final int PRINTER_ATTRIBUTE_MACHINE = 0x00080000;
public static final int PRINTER_ATTRIBUTE_FRIENDLY_NAME = 0x00100000;
public static final int PRINTER_ATTRIBUTE_TS_GENERIC_DRIVER = 0x00200000;
public static final int PRINTER_CHANGE_ADD_PRINTER = 0x00000001;
public static final int PRINTER_CHANGE_SET_PRINTER = 0x00000002;
public static final int PRINTER_CHANGE_DELETE_PRINTER = 0x00000004;
public static final int PRINTER_CHANGE_FAILED_CONNECTION_PRINTER = 0x00000008;
public static final int PRINTER_CHANGE_PRINTER = 0x000000FF;
public static final int PRINTER_CHANGE_ADD_JOB = 0x00000100;
public static final int PRINTER_CHANGE_SET_JOB = 0x00000200;
public static final int PRINTER_CHANGE_DELETE_JOB = 0x00000400;
public static final int PRINTER_CHANGE_WRITE_JOB = 0x00000800;
public static final int PRINTER_CHANGE_JOB = 0x0000FF00;
public static final int PRINTER_CHANGE_ADD_FORM = 0x00010000;
public static final int PRINTER_CHANGE_SET_FORM = 0x00020000;
public static final int PRINTER_CHANGE_DELETE_FORM = 0x00040000;
public static final int PRINTER_CHANGE_FORM = 0x00070000;
public static final int PRINTER_CHANGE_ADD_PORT = 0x00100000;
public static final int PRINTER_CHANGE_CONFIGURE_PORT = 0x00200000;
public static final int PRINTER_CHANGE_DELETE_PORT = 0x00400000;
public static final int PRINTER_CHANGE_PORT = 0x00700000;
public static final int PRINTER_CHANGE_ADD_PRINT_PROCESSOR = 0x01000000;
public static final int PRINTER_CHANGE_DELETE_PRINT_PROCESSOR = 0x04000000;
public static final int PRINTER_CHANGE_PRINT_PROCESSOR = 0x07000000;
public static final int PRINTER_CHANGE_SERVER = 0x08000000;
public static final int PRINTER_CHANGE_ADD_PRINTER_DRIVER = 0x10000000;
public static final int PRINTER_CHANGE_SET_PRINTER_DRIVER = 0x20000000;
public static final int PRINTER_CHANGE_DELETE_PRINTER_DRIVER = 0x40000000;
public static final int PRINTER_CHANGE_PRINTER_DRIVER = 0x70000000;
public static final int PRINTER_CHANGE_TIMEOUT = 0x80000000;
public static final int PRINTER_CHANGE_ALL_WIN7 = 0x7F77FFFF;
public static final int PRINTER_CHANGE_ALL = 0x7777FFFF;
public static final int PRINTER_ENUM_DEFAULT = 0x00000001;
public static final int PRINTER_ENUM_LOCAL = 0x00000002;
public static final int PRINTER_ENUM_CONNECTIONS = 0x00000004;
public static final int PRINTER_ENUM_FAVORITE = 0x00000004;
public static final int PRINTER_ENUM_NAME = 0x00000008;
public static final int PRINTER_ENUM_REMOTE = 0x00000010;
public static final int PRINTER_ENUM_SHARED = 0x00000020;
public static final int PRINTER_ENUM_NETWORK = 0x00000040;
public static final int PRINTER_ENUM_EXPAND = 0x00004000;
public static final int PRINTER_ENUM_CONTAINER = 0x00008000;
public static final int PRINTER_ENUM_ICONMASK = 0x00ff0000;
public static final int PRINTER_ENUM_ICON1 = 0x00010000;
public static final int PRINTER_ENUM_ICON2 = 0x00020000;
public static final int PRINTER_ENUM_ICON3 = 0x00040000;
public static final int PRINTER_ENUM_ICON4 = 0x00080000;
public static final int PRINTER_ENUM_ICON5 = 0x00100000;
public static final int PRINTER_ENUM_ICON6 = 0x00200000;
public static final int PRINTER_ENUM_ICON7 = 0x00400000;
public static final int PRINTER_ENUM_ICON8 = 0x00800000;
public static final int PRINTER_ENUM_HIDE = 0x01000000;
public static final int PRINTER_CONTROL_PAUSE = 0x01;
public static final int PRINTER_CONTROL_PURGE = 0x02;
public static final int PRINTER_CONTROL_RESUME = 0x03;
public static final int PRINTER_CONTROL_SET_STATUS = 0x04;
public static final int PRINTER_NOTIFY_OPTIONS_REFRESH = 0x01;
public static final int PRINTER_NOTIFY_INFO_DISCARDED = 0x01;
public static final int PRINTER_NOTIFY_TYPE = 0x00;
public static final int JOB_NOTIFY_TYPE = 0x01;
public static final int JOB_CONTROL_PAUSE = 0x01;
public static final int JOB_CONTROL_RESUME = 0x02;
public static final int JOB_CONTROL_CANCEL = 0x03;
public static final int JOB_CONTROL_RESTART = 0x04;
public static final int JOB_CONTROL_DELETE = 0x05;
public static final int JOB_CONTROL_SENT_TO_PRINTER = 0x06;
public static final int JOB_CONTROL_LAST_PAGE_EJECTED = 0x07;
public static final int JOB_CONTROL_RETAIN = 0x08;
public static final int JOB_CONTROL_RELEASE = 0x09;
public static final short PRINTER_NOTIFY_FIELD_SERVER_NAME = 0x00;
public static final short PRINTER_NOTIFY_FIELD_PRINTER_NAME = 0x01;
public static final short PRINTER_NOTIFY_FIELD_SHARE_NAME = 0x02;
public static final short PRINTER_NOTIFY_FIELD_PORT_NAME = 0x03;
public static final short PRINTER_NOTIFY_FIELD_DRIVER_NAME = 0x04;
public static final short PRINTER_NOTIFY_FIELD_COMMENT = 0x05;
public static final short PRINTER_NOTIFY_FIELD_LOCATION = 0x06;
public static final short PRINTER_NOTIFY_FIELD_DEVMODE = 0x07;
public static final short PRINTER_NOTIFY_FIELD_SEPFILE = 0x08;
public static final short PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR = 0x09;
public static final short PRINTER_NOTIFY_FIELD_PARAMETERS = 0x0A;
public static final short PRINTER_NOTIFY_FIELD_DATATYPE = 0x0B;
public static final short PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR = 0x0C;
public static final short PRINTER_NOTIFY_FIELD_ATTRIBUTES = 0x0D;
public static final short PRINTER_NOTIFY_FIELD_PRIORITY = 0x0E;
public static final short PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY = 0x0F;
public static final short PRINTER_NOTIFY_FIELD_START_TIME = 0x10;
public static final short PRINTER_NOTIFY_FIELD_UNTIL_TIME = 0x11;
public static final short PRINTER_NOTIFY_FIELD_STATUS = 0x12;
public static final short PRINTER_NOTIFY_FIELD_STATUS_STRING = 0x13;
public static final short PRINTER_NOTIFY_FIELD_CJOBS = 0x14;
public static final short PRINTER_NOTIFY_FIELD_AVERAGE_PPM = 0x15;
public static final short PRINTER_NOTIFY_FIELD_TOTAL_PAGES = 0x16;
public static final short PRINTER_NOTIFY_FIELD_PAGES_PRINTED = 0x17;
public static final short PRINTER_NOTIFY_FIELD_TOTAL_BYTES = 0x18;
public static final short PRINTER_NOTIFY_FIELD_BYTES_PRINTED = 0x19;
public static final short PRINTER_NOTIFY_FIELD_OBJECT_GUID = 0x1A;
public static final short PRINTER_NOTIFY_FIELD_FRIENDLY_NAME = 0x1B;
public static final short PRINTER_NOTIFY_FIELD_BRANCH_OFFICE_PRINTING = 0x1C;
public static final short JOB_NOTIFY_FIELD_PRINTER_NAME = 0x00;
public static final short JOB_NOTIFY_FIELD_MACHINE_NAME = 0x01;
public static final short JOB_NOTIFY_FIELD_PORT_NAME = 0x02;
public static final short JOB_NOTIFY_FIELD_USER_NAME = 0x03;
public static final short JOB_NOTIFY_FIELD_NOTIFY_NAME = 0x04;
public static final short JOB_NOTIFY_FIELD_DATATYPE = 0x05;
public static final short JOB_NOTIFY_FIELD_PRINT_PROCESSOR = 0x06;
public static final short JOB_NOTIFY_FIELD_PARAMETERS = 0x07;
public static final short JOB_NOTIFY_FIELD_DRIVER_NAME = 0x08;
public static final short JOB_NOTIFY_FIELD_DEVMODE = 0x09;
public static final short JOB_NOTIFY_FIELD_STATUS = 0x0A;
public static final short JOB_NOTIFY_FIELD_STATUS_STRING = 0x0B;
public static final short JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR = 0x0C;
public static final short JOB_NOTIFY_FIELD_DOCUMENT = 0x0D;
public static final short JOB_NOTIFY_FIELD_PRIORITY = 0x0E;
public static final short JOB_NOTIFY_FIELD_POSITION = 0x0F;
public static final short JOB_NOTIFY_FIELD_SUBMITTED = 0x10;
public static final short JOB_NOTIFY_FIELD_START_TIME = 0x11;
public static final short JOB_NOTIFY_FIELD_UNTIL_TIME = 0x12;
public static final short JOB_NOTIFY_FIELD_TIME = 0x13;
public static final short JOB_NOTIFY_FIELD_TOTAL_PAGES = 0x14;
public static final short JOB_NOTIFY_FIELD_PAGES_PRINTED = 0x15;
public static final short JOB_NOTIFY_FIELD_TOTAL_BYTES = 0x16;
public static final short JOB_NOTIFY_FIELD_BYTES_PRINTED = 0x17;
public static final short JOB_NOTIFY_FIELD_REMOTE_JOB_ID = 0x18;
public static final int PRINTER_NOTIFY_CATEGORY_ALL = 0x001000;
public static final int PRINTER_NOTIFY_CATEGORY_3D = 0x002000;
/**
* The EnumPrinters function enumerates available printers, print servers,
* domains, or print providers.
*
* @param Flags
* The types of print objects that the function should enumerate.
* @param Name
* If Level is 1, Flags contains PRINTER_ENUM_NAME, and Name is
* non-NULL, then Name is a pointer to a null-terminated string
* that specifies the name of the object to enumerate. This
* string can be the name of a server, a domain, or a print
* provider. If Level is 1, Flags contains PRINTER_ENUM_NAME, and
* Name is NULL, then the function enumerates the available print
* providers. If Level is 1, Flags contains PRINTER_ENUM_REMOTE,
* and Name is NULL, then the function enumerates the printers in
* the user's domain. If Level is 2 or 5,Name is a pointer to a
* null-terminated string that specifies the name of a server
* whose printers are to be enumerated. If this string is NULL,
* then the function enumerates the printers installed on the
* local computer. If Level is 4, Name should be NULL. The
* function always queries on the local computer. When Name is
* NULL, setting Flags to PRINTER_ENUM_LOCAL |
* PRINTER_ENUM_CONNECTIONS enumerates printers that are
* installed on the local machine. These printers include those
* that are physically attached to the local machine as well as
* remote printers to which it has a network connection. When
* Name is not NULL, setting Flags to PRINTER_ENUM_LOCAL |
* PRINTER_ENUM_NAME enumerates the local printers that are
* installed on the server Name.
* @param Level
* The type of data structures pointed to by pPrinterEnum. Valid
* values are 1, 2, 4, and 5, which correspond to the
* PRINTER_INFO_1, PRINTER_INFO_2 , PRINTER_INFO_4, and
* PRINTER_INFO_5 data structures.
* @param pPrinterEnum
* A pointer to a buffer that receives an array of
* PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_4, or
* PRINTER_INFO_5 structures. Each structure contains data that
* describes an available print object. If Level is 1, the array
* contains PRINTER_INFO_1 structures. If Level is 2, the array
* contains PRINTER_INFO_2 structures. If Level is 4, the array
* contains PRINTER_INFO_4 structures. If Level is 5, the array
* contains PRINTER_INFO_5 structures. The buffer must be large
* enough to receive the array of data structures and any strings
* or other data to which the structure members point. If the
* buffer is too small, the pcbNeeded parameter returns the
* required buffer size.
* @param cbBuf
* The size, in bytes, of the buffer pointed to by pPrinterEnum.
* @param pcbNeeded
* A pointer to a value that receives the number of bytes copied
* if the function succeeds or the number of bytes required if
* cbBuf is too small.
* @param pcReturned
* A pointer to a value that receives the number of
* PRINTER_INFO_1, PRINTER_INFO_2 , PRINTER_INFO_4, or
* PRINTER_INFO_5 structures that the function returns in the
* array to which pPrinterEnum points.
* @return If the function succeeds, the return value is a nonzero value. If
* the function fails, the return value is zero.
*
* @see <a href=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/dd162692(v=vs.85).aspx">
* EnumPrinters function</a>
*/
boolean EnumPrinters(int Flags, String Name, int Level,
Pointer pPrinterEnum, int cbBuf, IntByReference pcbNeeded,
IntByReference pcReturned);
/**
* The GetPrinter function retrieves information about a specified printer.
*
* @param hPrinter A handle to the printer for which the function retrieves
* information. Use the OpenPrinter or AddPrinter function
* to retrieve a printer handle.
* @param Level The level or type of structure that the function stores
* into the buffer pointed to by pPrinter. This value can
* be 1, 2, 3, 4, 5, 6, 7, 8 or 9.
* @param pPrinter A pointer to a buffer that receives a structure
* containing information about the specified printer. The
* buffer must be large enough to receive the structure and
* any strings or other data to which the structure members
* point. If the buffer is too small, the pcbNeeded
* parameter returns the required buffer size. The type of
* structure is determined by the value of Level.
* @param cbBuf The size, in bytes, of the buffer pointed to by
* pPrinter.
* @param pcbNeeded A pointer to a variable that the function sets to the
* size, in bytes, of the printer information. If cbBuf is
* smaller than this value, GetPrinter fails, and the value
* represents the required buffer size. If cbBuf is equal
* to or greater than this value, GetPrinter succeeds, and
* the value represents the number of bytes stored in the
* buffer.
*
* @return If the function succeeds, the return value is a nonzero value. If
* the function fails, the return value is zero.
*
* @see <a href=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/dd144911(v=vs.85).aspx">
* GetPrinter function</a>
*/
boolean GetPrinter(HANDLE hPrinter, int Level, Pointer pPrinter, int cbBuf, IntByReference pcbNeeded);
/**
* The PRINTER_INFO_1 structure specifies general printer information.
*
* @see <a href=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/dd162844(v=vs.85).aspx">
* PRINTER_INFO_1 structure</a>
*/
@FieldOrder({"Flags", "pDescription", "pName", "pComment"})
public static class PRINTER_INFO_1 extends Structure {
/**
* Specifies information about the returned data. Following are the
* values for this member.
*/
public int Flags;
/**
* Pointer to a null-terminated string that describes the contents of
* the structure.
*/
public String pDescription;
/**
* Pointer to a null-terminated string that names the contents of the
* structure.
*/
public String pName;
/**
* Pointer to a null-terminated string that contains additional data
* describing the structure.
*/
public String pComment;
public PRINTER_INFO_1() {
super();
}
public PRINTER_INFO_1(int size) {
super(new Memory(size));
}
}
/**
* The PRINTER_INFO_2 structure specifies detailed printer information.
*
* @author Ivan Ridao Freitas, Padrus
* @see <a href=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/dd162845(v=vs.85).aspx">
* PRINTER_INFO_2 structure</a>
*/
@FieldOrder({"pServerName", "pPrinterName", "pShareName",
"pPortName", "pDriverName", "pComment", "pLocation", "pDevMode", "pSepFile", "pPrintProcessor",
"pDatatype", "pParameters", "pSecurityDescriptor", "Attributes", "Priority", "DefaultPriority",
"StartTime", "UntilTime", "Status", "cJobs", "AveragePPM"})
public static class PRINTER_INFO_2 extends Structure {
/**
* A pointer to a null-terminated string identifying the server that
* controls the printer. If this string is NULL, the printer is
* controlled locally.
*/
public String pServerName;
/**
* A pointer to a null-terminated string that specifies the name of the
* printer.
*/
public String pPrinterName;
/**
* A pointer to a null-terminated string that identifies the share point
* for the printer. (This string is used only if the
* PRINTER_ATTRIBUTE_SHARED constant was set for the Attributes member.)
*/
public String pShareName;
/**
* A pointer to a null-terminated string that identifies the port(s)
* used to transmit data to the printer. If a printer is connected to
* more than one port, the names of each port must be separated by
* commas (for example, "LPT1:,LPT2:,LPT3:").
*/
public String pPortName;
/**
* A pointer to a null-terminated string that specifies the name of the
* printer driver.
*/
public String pDriverName;
/**
* A pointer to a null-terminated string that provides a brief
* description of the printer.
*/
public String pComment;
/**
* A pointer to a null-terminated string that specifies the physical
* location of the printer (for example, "Bldg. 38, Room 1164").
*/
public String pLocation;
/**
* A pointer to a DEVMODE structure that defines default printer data
* such as the paper orientation and the resolution.
*/
public INT_PTR pDevMode;
/**
* A pointer to a null-terminated string that specifies the name of the
* file used to create the separator page. This page is used to separate
* print jobs sent to the printer.
*/
public String pSepFile;
/**
* A pointer to a null-terminated string that specifies the name of the
* print processor used by the printer. You can use the
* EnumPrintProcessors function to obtain a list of print processors
* installed on a server.
*/
public String pPrintProcessor;
/**
* A pointer to a null-terminated string that specifies the data type
* used to record the print job. You can use the
* EnumPrintProcessorDatatypes function to obtain a list of data types
* supported by a specific print processor.
*/
public String pDatatype;
/**
* A pointer to a null-terminated string that specifies the default
* print-processor parameters.
*/
public String pParameters;
/**
* A pointer to a SECURITY_DESCRIPTOR structure for the printer. This
* member may be NULL.
*/
public INT_PTR pSecurityDescriptor;
/**
* The printer attributes. This member can be any reasonable combination
* of the values PRINTER_ATTRIBUTE_XXX.
*/
public int Attributes;
/**
* A priority value that the spooler uses to route print jobs.
*/
public int Priority;
/**
* The default priority value assigned to each print job.
*/
public int DefaultPriority;
/**
* The earliest time at which the printer will print a job. This value
* is expressed as minutes elapsed since 12:00 AM GMT (Greenwich Mean
* Time).
*/
public int StartTime;
/**
* The latest time at which the printer will print a job. This value is
* expressed as minutes elapsed since 12:00 AM GMT (Greenwich Mean
* Time).
*/
public int UntilTime;
/**
* The printer status. This member can be any reasonable combination of
* the values PRINTER_STATUS_XXX.
*/
public int Status;
/**
* The number of print jobs that have been queued for the printer.
*/
public int cJobs;
/**
* The average number of pages per minute that have been printed on the
* printer.
*/
public int AveragePPM;
public PRINTER_INFO_2() {
super();
}
public PRINTER_INFO_2(int size) {
super(new Memory(size));
}
/**
* Checks if the printer attributes have one of the values
* PRINTER_ATTRIBUTE_XXX.
*/
public boolean hasAttribute(int value) {
return (Attributes & value) == value;
}
}
/**
* The PRINTER_INFO_4 structure specifies general printer information.
* <p>
* The structure can be used to retrieve minimal printer information on a
* call to EnumPrinters. Such a call is a fast and easy way to retrieve the
* names and attributes of all locally installed printers on a system and
* all remote printer connections that a user has established.
*
* @see <a href=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/dd162847(v=vs.85).aspx">
* PRINTER_INFO_4 structure</a>
*/
@FieldOrder({"pPrinterName", "pServerName", "Attributes"})
public static class PRINTER_INFO_4 extends Structure {
/**
* Pointer to a null-terminated string that specifies the name of the
* printer (local or remote).
*/
public String pPrinterName;
/**
* Pointer to a null-terminated string that is the name of the server.
*/
public String pServerName;
/**
* Specifies information about the returned data.
*/
public DWORD Attributes;
public PRINTER_INFO_4() {
super();
}
public PRINTER_INFO_4(int size) {
super(new Memory(size));
}
}
/**
* The PRINTER_DEFAULTS structure specifies the default data type,
* environment, initialization data, and access rights for a printer.
*
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd162839(v=vs.85).aspx">PRINTER_DEFAULTS structure</a>
*/
@FieldOrder({"pDatatype", "pDevMode", "DesiredAccess"})
public class LPPRINTER_DEFAULTS extends Structure {
/**
* Pointer to a null-terminated string that specifies the default data
* type for a printer.
*/
public String pDatatype;
/**
* Pointer to a DEVMODE structure that identifies the default
* environment and initialization data for a printer.
*/
public Pointer pDevMode;
/**
* Specifies desired access rights for a printer. The OpenPrinter
* function uses this member to set access rights to the printer. These
* rights can affect the operation of the SetPrinter and DeletePrinter
* functions.
*/
public int DesiredAccess;
}
/**
* The OpenPrinter function retrieves a handle to the specified printer or
* print server or other types of handles in the print subsystem.
*
* @param pPrinterName
* [in] A pointer to a null-terminated string that specifies the
* name of the printer or print server, the printer object, the
* XcvMonitor, or the XcvPort. For a printer object use:
* PrinterName, Job xxxx. For an XcvMonitor, use: ServerName,
* XcvMonitor MonitorName. For an XcvPort, use: ServerName,
* XcvPort PortName. If NULL, it indicates the local printer
* server.
* @param phPrinter
* [out] A pointer to a variable that receives a handle (not
* thread safe) to the open printer or print server object. The
* phPrinter parameter can return an Xcv handle for use with the
* XcvData function. For more information about XcvData, see the
* DDK.
* @param pDefault
* [in] A pointer to a PRINTER_DEFAULTS structure. This value can
* be NULL.
* @return If the function succeeds, the return value is a nonzero value. If
* the function fails, the return value is zero.
*
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162751(v=vs.85).aspx">OpenPrinter function</a>
*/
boolean OpenPrinter(
// _In_
String pPrinterName,
// _Out_
HANDLEByReference phPrinter,
// _In_
LPPRINTER_DEFAULTS pDefault);
/**
* The ClosePrinter function closes the specified printer object.<br>
* Note This is a blocking or synchronous function and might not return
* immediately.<br>
* How quickly this function returns depends on run-time factors such as
* network status, print server configuration, and printer driver
* implementation-factors that are difficult to predict when writing an
* application. Calling this function from a thread that manages interaction
* with the user interface could make the application appear to be
* unresponsive.
* <p>
* When the ClosePrinter function returns, the handle hPrinter is invalid,
* regardless of whether the function has succeeded or failed.
*
* @param hPrinter A handle to the printer object to be closed. This handle
* is returned by the OpenPrinter or AddPrinter function.
*
* @return If the function succeeds, the return value is a nonzero value. If
* the function fails, the return value is zero.
*
* @see <a href=
* "http://msdn.microsoft.com/en-us/library/windows/desktop/dd162751(v=vs.85).aspx">
* ClosePrinter function</a>
*/
boolean ClosePrinter(HANDLE hPrinter);
/**
* The PRINTER_NOTIFY_OPTIONS structure specifies options for a change
* notification object that monitors a printer or print server.
*
* @see
* <a href="https://docs.microsoft.com/en-us/windows/win32/printdocs/printer-notify-options">
* PRINTER_NOTIFY_OPTIONS structure
* </a>
*/
@Structure.FieldOrder({ "Version", "Flags", "Count", "pTypes" })
public class PRINTER_NOTIFY_OPTIONS extends Structure {
/**
* The version of this structure. Set this member to 2.
*/
public int Version = 2;
/**
* A bit flag. If you set the PRINTER_NOTIFY_OPTIONS_REFRESH flag in a
* call to the FindNextPrinterChangeNotification function, the function
* provides current data for all monitored printer information fields.
* The FindFirstPrinterChangeNotification function ignores the Flags
* member.
*/
public int Flags;
/**
* The number of elements in the pTypes array.
*/
public int Count;
/**
* A pointer to an array of PRINTER_NOTIFY_OPTIONS_TYPE structures. Use
* one element of this array to specify the printer information fields
* to monitor, and one element to specify the job information fields to
* monitor. You can monitor either printer information, job
* information, or both.
*/
public PRINTER_NOTIFY_OPTIONS_TYPE.ByReference pTypes;
}
/**
* The PRINTER_NOTIFY_OPTIONS_TYPE structure specifies the set of printer
* or job information fields to be monitored by a printer change
* notification object.
*
* @see
* <a href="https://docs.microsoft.com/en-us/windows/win32/printdocs/printer-notify-options-type">
* PRINTER_NOTIFY_OPTIONS_TYPE structure
* </a>
*/
@Structure.FieldOrder({ "Type", "Reserved0", "Reserved1", "Reserved2",
"Count", "pFields" })
public class PRINTER_NOTIFY_OPTIONS_TYPE extends Structure {
public static class ByReference extends PRINTER_NOTIFY_OPTIONS_TYPE
implements Structure.ByReference {
}
/**
* The type to be watched.
*/
public short Type;
/**
* Reserved.
*/
public short Reserved0;
/**
* Reserved.
*/
public int Reserved1;
/**
* Reserved.
*/
public int Reserved2;
/**
* The number of elements in the pFields array.
*/
public int Count;
/**
* A pointer to an array of values. Each element of the array specifies
* a job or printer information field of interest.
*/
public Pointer pFields;
public void setFields(short[] fields) {
final long shortSizeInBytes = 2L;
Memory fieldsMemory = new Memory(fields.length * shortSizeInBytes);
fieldsMemory.write(0, fields, 0, fields.length);
pFields = fieldsMemory;
Count = fields.length;
}
public short[] getFields() {
return pFields.getShortArray(0, Count);
}
}
/**
* The PRINTER_NOTIFY_INFO structure contains printer information returned
* by the FindNextPrinterChangeNotification function. The function returns
* this information after a wait operation on a printer change notification
* object has been satisfied.
*
* @see
* <a href="https://docs.microsoft.com/en-us/windows/win32/printdocs/printer-notify-info">
* PRINTER_NOTIFY_INFO structure
* </a>
*/
@Structure.FieldOrder({ "Version", "Flags", "Count", "aData" })
public class PRINTER_NOTIFY_INFO extends Structure {
/**
* The version of this structure. Set this member to 2.
*/
public int Version;
/**
* A bit flag that indicates the state of the notification structure. If
* the PRINTER_NOTIFY_INFO_DISCARDED bit is set, it indicates that some
* notifications had to be discarded.
*/
public int Flags;
/**
* The number of PRINTER_NOTIFY_INFO_DATA elements in the aData array.
*/
public int Count;
/**
* An array of PRINTER_NOTIFY_INFO_DATA structures. Each element of the
* array identifies a single job or printer information field, and
* provides the current data for that field.
*/
public PRINTER_NOTIFY_INFO_DATA[] aData =
new PRINTER_NOTIFY_INFO_DATA[1];
@Override
public void read() {
int count = (Integer) readField("Count");
aData = new PRINTER_NOTIFY_INFO_DATA[count];
if (count == 0) {
Count = count;
Version = (Integer) readField("Version");
Flags = (Integer) readField("Flags");
} else {
super.read();
}
}
}
/**
* A struct containing non-numeric notification data - conditional content
* of a {@link NOTIFY_DATA} union.
*/
@Structure.FieldOrder({ "cbBuf", "pBuf" })
public class NOTIFY_DATA_DATA extends Structure {
/**
* Indicates the size, in bytes, of the buffer pointed to by pBuf.
*/
public int cbBuf;
/**
* Pointer to a buffer that contains the field's current data.
*/
public Pointer pBuf;
}
/**
* A union of data information based on the Type and Field members of
* {@link PRINTER_NOTIFY_INFO_DATA}
*/
public class NOTIFY_DATA extends Union {
/**
* Set if the notification data is numeric.
*
* An array of two DWORD values. For information fields that use only a
* single DWORD, the data is in adwData [0].
*/
public int[] adwData = new int[2];
/**
* Set if the notification data is non-numeric.
*/
public NOTIFY_DATA_DATA Data;
}
/**
* The PRINTER_NOTIFY_INFO_DATA structure identifies a job or printer
* information field and provides the current data for that field.
*
* @see
* <a href="https://docs.microsoft.com/en-us/windows/win32/printdocs/printer-notify-info-data">
* PRINTER_NOTIFY_INFO_DATA structure
* </a>
*/
@Structure.FieldOrder({ "Type", "Field", "Reserved", "Id", "NotifyData" })
public class PRINTER_NOTIFY_INFO_DATA extends Structure {
/**
* Indicates the type of information provided.
*/
public short Type;
/**
* Indicates the field that changed.
*/
public short Field;
/**
* Reserved.
*/
public int Reserved;
/**
* Indicates the job identifier if the Type member specifies
* JOB_NOTIFY_TYPE. If the Type member specifies PRINTER_NOTIFY_TYPE,
* this member is undefined.
*/
public int Id;
/**
* A union of data information based on the Type and Field members.
*/
public NOTIFY_DATA NotifyData;
@Override
public void read() {
super.read();
boolean numericData;
if (Type == PRINTER_NOTIFY_TYPE) {
switch (Field) {
case PRINTER_NOTIFY_FIELD_ATTRIBUTES:
// Fall-through
case PRINTER_NOTIFY_FIELD_PRIORITY:
// Fall-through
case PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY:
// Fall-through
case PRINTER_NOTIFY_FIELD_START_TIME:
// Fall-through
case PRINTER_NOTIFY_FIELD_UNTIL_TIME:
// Fall-through
case PRINTER_NOTIFY_FIELD_STATUS:
// Fall-through
case PRINTER_NOTIFY_FIELD_CJOBS:
// Fall-through
case PRINTER_NOTIFY_FIELD_AVERAGE_PPM:
numericData = true;
default:
numericData = false;
}
} else {
switch (Field) {
case JOB_NOTIFY_FIELD_STATUS:
// Fall-through
case JOB_NOTIFY_FIELD_PRIORITY:
// Fall-through
case JOB_NOTIFY_FIELD_POSITION:
// Fall-through
case JOB_NOTIFY_FIELD_START_TIME:
// Fall-through
case JOB_NOTIFY_FIELD_UNTIL_TIME:
// Fall-through
case JOB_NOTIFY_FIELD_TIME:
// Fall-through
case JOB_NOTIFY_FIELD_TOTAL_PAGES:
// Fall-through
case JOB_NOTIFY_FIELD_PAGES_PRINTED:
// Fall-through
case JOB_NOTIFY_FIELD_TOTAL_BYTES:
// Fall-through
case JOB_NOTIFY_FIELD_BYTES_PRINTED:
numericData = true;
default:
numericData = false;
}
}
if (numericData) {
NotifyData.setType(int[].class);
} else {
NotifyData.setType(NOTIFY_DATA_DATA.class);
}
NotifyData.read();
}
}
@Deprecated
HANDLE FindFirstPrinterChangeNotification(
// _In_
HANDLE hPrinter,
int fdwFilter,
int fdwOptions,
// _In_opt_
LPVOID pPrinterNotifyOptions);
/**
* The FindFirstPrinterChangeNotification function creates a change
* notification object and returns a handle to the object. You can then use
* this handle in a call to one of the wait functions to monitor changes to
* the printer or print server. The FindFirstPrinterChangeNotification call
* specifies the type of changes to be monitored. You can specify a set of
* conditions to monitor for changes, a set of printer information fields to
* monitor, or both. A wait operation on the change notification handle
* succeeds when one of the specified changes occurs in the specified
* printer or print server. You then call the
* FindNextPrinterChangeNotification function to retrieve information about
* the change, and to reset the change notification object for use in the
* next wait operation.
*
* @param hPrinter
* [in] A handle to the printer or print server that you want to
* monitor. Use the OpenPrinter or AddPrinter function to
* retrieve a printer handle.
* @param fdwFilter
* The conditions that will cause the change notification object
* to enter a signaled state. A change notification occurs when
* one or more of the specified conditions are met. The fdwFilter
* parameter can be zero if pPrinterNotifyOptions is non-NULL.
*
* @param fdwOptions
* Reserved; must be zero.
* @param pPrinterNotifyOptions
* [in, optional] A pointer to a PRINTER_NOTIFY_OPTIONS
* structure. The pTypes member of this structure is an array of
* one or more PRINTER_NOTIFY_OPTIONS_TYPE structures, each of which
* specifies a printer information field to monitor. A change
* notification occurs when one or more of the specified fields
* changes. When a change occurs, the
* FindNextPrinterChangeNotification function can retrieve the
* new printer information. This parameter can be NULL if
* fdwFilter is nonzero. For a list of fields that can be
* monitored, see PRINTER_NOTIFY_OPTIONS_TYPE.
*
* @return If the function succeeds, the return value is a handle to a
* change notification object associated with the specified printer
* or print server. If the function fails, the return value is
* INVALID_HANDLE_VALUE.
*