forked from java-native-access/jna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Kernel32.java
4150 lines (3974 loc) · 217 KB
/
Kernel32.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) 2007, 2013 Timothy Wall, Markus Karg, 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.LastErrorException;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
/**
* Interface definitions for <code>kernel32.dll</code>. Includes additional
* alternate mappings from {@link WinNT} which make use of NIO buffers,
* {@link Wincon} for console API.
*/
public interface Kernel32 extends StdCallLibrary, WinNT, Wincon {
/** The instance. */
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.DEFAULT_OPTIONS);
/**
* <strong>LOAD_LIBRARY_AS_DATAFILE</strong> <br>
* 0x00000002<br>
* If this value is used, the system maps the file into the calling
* process's virtual address space as if it were a data file.<br>
* Nothing is done to execute or prepare to execute the mapped file.<br>
* Therefore, you cannot call functions like <a href=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197(v=vs.85).aspx">
* <strong xmlns="http://www.w3.org/1999/xhtml">GetModuleFileName</strong>
* </a>, <a href=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/ms683199(v=vs.85).aspx">
* <strong xmlns="http://www.w3.org/1999/xhtml">GetModuleHandle</strong></a>
* or <a href=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/ms683212(v=vs.85).aspx">
* <strong xmlns="http://www.w3.org/1999/xhtml">GetProcAddress</strong></a>
* with this DLL. Using this value causes writes to read-only memory to
* raise an access violation.<br>
* Use this flag when you want to load a DLL only to extract messages or
* resources from it.<br>
* This value can be used with
* <strong>LOAD_LIBRARY_AS_IMAGE_RESOURCE</strong>. For more information,
* see Remarks.
*/
int LOAD_LIBRARY_AS_DATAFILE = 0x2;
/**
* Reads data from the specified file or input/output (I/O) device. Reads
* occur at the position specified by the file pointer if supported by the
* device.
*
* This function is designed for both synchronous and asynchronous
* operations. For a similar function designed solely for asynchronous
* operation, see ReadFileEx
*
* @param hFile
* A handle to the device (for example, a file, file stream,
* physical disk, volume, console buffer, tape drive, socket,
* communications resource, mailslot, or pipe).
* @param lpBuffer
* A pointer to the buffer that receives the data read from a
* file or device.
* @param nNumberOfBytesToRead
* The maximum number of bytes to be read.
* @param lpNumberOfBytesRead
* A pointer to the variable that receives the number of bytes
* read when using a synchronous hFile parameter
* @param lpOverlapped
* A pointer to an OVERLAPPED structure is required if the hFile
* parameter was opened with FILE_FLAG_OVERLAPPED, otherwise it
* can be NULL.
* @return If the function succeeds, the return value is nonzero (TRUE). If
* the function fails, or is completing asynchronously, the return
* value is zero (FALSE). To get extended error information, call
* the GetLastError function.
*
* Note The GetLastError code ERROR_IO_PENDING is not a failure; it
* designates the read operation is pending completion
* asynchronously. For more information, see Remarks.
*/
boolean ReadFile(HANDLE hFile, byte[] lpBuffer, int nNumberOfBytesToRead,
IntByReference lpNumberOfBytesRead, WinBase.OVERLAPPED lpOverlapped);
/**
* Frees the specified local memory object and invalidates its handle.
*
* @param hMem
* A handle to the local memory object. If the <tt>hMem</tt> parameter
* is NULL, {@code LocalFree} ignores the parameter and returns NULL.
* @return If the function succeeds, the return value is NULL. If the
* function fails, the return value is equal to a handle to the
* local memory object. To get extended error information, call
* {@code GetLastError}.
* @see <A HREF="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366730(v=vs.85).aspx">LocalFree</A>
*/
Pointer LocalFree(Pointer hMem);
/**
* Frees the specified global memory object and invalidates its handle.
*
* @param hGlobal
* A handle to the global memory object.
* @return If the function succeeds, the return value is NULL If the
* function fails, the return value is equal to a handle to the
* global memory object. To get extended error information, call
* {@code GetLastError}.
* @see <A HREF="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366579(v=vs.85).aspx">GlobalFree</A>
*/
Pointer GlobalFree(Pointer hGlobal);
/**
* The GetModuleHandle function retrieves a module handle for the specified
* module if the file has been mapped into the address space of the calling
* process.
*
* @param name
* Pointer to a null-terminated string that contains the name of
* the module (either a .dll or .exe file).
* @return If the function succeeds, the return value is a handle to the
* specified module. If the function fails, the return value is
* NULL. To get extended error information, call GetLastError.
*/
HMODULE GetModuleHandle(String name);
/**
* The GetSystemTime function retrieves the current system date and time.
* The system time is expressed in Coordinated Universal Time (UTC).
*
* @param lpSystemTime
* Pointer to a {@link WinBase.SYSTEMTIME} structure to receive the current
* system date and time.
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724390(v=vs.85).aspx">GetSystemTime documentation</a>
*/
void GetSystemTime(SYSTEMTIME lpSystemTime);
/**
* The SetSystemTime function modifies the current system date and time.
* The system time is expressed in Coordinated Universal Time (UTC).
*
* @param lpSystemTime
* Pointer to a {@link WinBase.SYSTEMTIME} structure holding the new
* system date and time. <B>Note:</B> The {@code wDayOfWeek}
* member of the SYSTEMTIME structure is ignored.
* @return {@code true} if the function succeeds, {@code false} otherwise.
* If the function fails, call {@link #GetLastError()} to get extended error
* information.
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724942(v=vs.85).aspx">SetSystemTime documentation</a>
*/
boolean SetSystemTime(SYSTEMTIME lpSystemTime);
/**
* Retrieves the current local date and time.
*
* @param lpSystemTime
* A pointer to a {@link WinBase.SYSTEMTIME} structure to receive the current
* local date and time.
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724338(v=vs.85).aspx">GetLocalTime documentation</a>
*/
void GetLocalTime(WinBase.SYSTEMTIME lpSystemTime);
/**
* Sets the current local time and date
*
* @param lpSystemTime
* Pointer to a {@link WinBase.SYSTEMTIME} structure holding the new
* system date and time. <B>Note:</B> The {@code wDayOfWeek}
* member of the SYSTEMTIME structure is ignored.
* @return {@code true} if the function succeeds, {@code false} otherwise.
* If the function fails, call {@link #GetLastError()} to get extended error
* information.
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724936(v=vs.85).aspx">SetLocalTime documentation</a>
*/
boolean SetLocalTime(SYSTEMTIME lpSystemTime);
/**
* Retrieves system timing information. On a multiprocessor system, the
* values returned are the sum of the designated times across all
* processors.
*
* @param lpIdleTime
* A pointer to a {@link WinBase.FILETIME} structure that
* receives the amount of time that the system has been idle.
* @param lpKernelTime
* A pointer to a {@link WinBase.FILETIME} structure that
* receives the amount of time that the system has spent
* executing in Kernel mode (including all threads in all
* processes, on all processors). This time value also includes
* the amount of time the system has been idle.
* @param lpUserTime
* A pointer to a {@link WinBase.FILETIME} structure that
* receives the amount of time that the system has spent
* executing in User mode (including all threads in all
* processes, on all processors).
* @return {@code true} if the function succeeds, {@code false} otherwise.
* If the function fails, call {@link #GetLastError()} to get extended error
* information.
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724400(v=vs.85).aspx">GetSystemTimes documentation</a>
*/
boolean GetSystemTimes(WinBase.FILETIME lpIdleTime, WinBase.FILETIME lpKernelTime, WinBase.FILETIME lpUserTime);
/**
* The GetTickCount function retrieves the number of milliseconds that have
* elapsed since the system was started, up to 49.7 days.
*
* @return Number of milliseconds that have elapsed since the system was
* started.
*/
int GetTickCount();
/**
* The GetTickCount64 function retrieves the number of milliseconds that
* have elapsed since the system was started.
*
* @return Number of milliseconds that have elapsed since the system was
* started.
*/
long GetTickCount64();
/**
* The GetCurrentThreadId function retrieves the thread identifier of the
* calling thread.
*
* @return The return value is the thread identifier of the calling thread.
*/
int GetCurrentThreadId();
/**
* The GetCurrentThread function retrieves a pseudo handle for the current
* thread.
*
* @return The return value is a pseudo handle for the current thread.
*/
HANDLE GetCurrentThread();
/**
* This function returns the process identifier of the calling process.
*
* @return The return value is the process identifier of the calling
* process.
*/
int GetCurrentProcessId();
/**
* This function returns a pseudohandle for the current process.
*
* @return The return value is a pseudohandle to the current process.
*/
HANDLE GetCurrentProcess();
/**
* The GetProcessId function retrieves the process identifier of the
* specified process.
*
* @param process
* Handle to the process. The handle must have the
* PROCESS_QUERY_INFORMATION access right.
* @return If the function succeeds, the return value is the process
* identifier of the specified process. If the function fails, the
* return value is zero. To get extended error information, call
* GetLastError.
*/
int GetProcessId(HANDLE process);
/**
* The GetProcessVersion function retrieves the major and minor version
* numbers of the system on which the specified process expects to run.
*
* @param processId
* Process identifier of the process of interest. A value of zero
* specifies the calling process.
* @return If the function succeeds, the return value is the version of the
* system on which the process expects to run. The high word of the
* return value contains the major version number. The low word of
* the return value contains the minor version number. If the
* function fails, the return value is zero. To get extended error
* information, call GetLastError. The function fails if ProcessId
* is an invalid value.
*/
int GetProcessVersion(int processId);
/**
* Retrieves the process affinity mask for the specified process and the system
* affinity mask for the system.
*
* @param hProcess
* A handle to the process whose affinity mask is desired.
* <p>
* This handle must have the {@link WinNT#PROCESS_QUERY_INFORMATION}
* or {@link WinNT#PROCESS_QUERY_LIMITED_INFORMATION} access right.
* @param lpProcessAffinityMask
* A pointer to a variable that receives the affinity mask for the
* specified process.
* @param lpSystemAffinityMask
* A pointer to a variable that receives the affinity mask for the
* system.
* @return If the function succeeds, returns {@code true} and the function sets
* the variables pointed to by {@code lpProcessAffinityMask} and
* {@code lpSystemAffinityMask} to the appropriate affinity masks.
* <p>
* On a system with more than 64 processors, if the threads of the
* calling process are in a single processor group, the function sets
* the variables pointed to by {@code lpProcessAffinityMask} and
* {@code lpSystemAffinityMask} to the process affinity mask and the
* processor mask of active logical processors for that group. If the
* calling process contains threads in multiple groups, the function
* returns zero for both affinity masks.
* <p>
* If the function fails, the return value is {@code false}, and the
* values of the variables pointed to by {@code lpProcessAffinityMask}
* and {@code lpSystemAffinityMask} are undefined. To get extended error
* information, call {@link #GetLastError()}.
*/
boolean GetProcessAffinityMask(HANDLE hProcess, ULONG_PTRByReference lpProcessAffinityMask,
ULONG_PTRByReference lpSystemAffinityMask);
/**
* Sets a processor affinity mask for the threads of the specified process.
*
* @param hProcess
* A handle to the process whose affinity mask is to be set. This
* handle must have the {@link WinNT#PROCESS_SET_INFORMATION} access
* right.
* @param dwProcessAffinityMask
* The affinity mask for the threads of the process.
* <p>
* On a system with more than 64 processors, the affinity mask must
* specify processors in a single processor group.
* @return If the function succeeds, the return value is {@code true}.
* <p>
* If the function fails, the return value is {@code false}. To get
* extended error information, call {@link #GetLastError()}.
* <p>
* If the process affinity mask requests a processor that is not
* configured in the system, the last error code is
* {@link WinError#ERROR_INVALID_PARAMETER}.
* <p>
* On a system with more than 64 processors, if the calling process
* contains threads in more than one processor group, the last error
* code is {@link WinError#ERROR_INVALID_PARAMETER}.
*/
boolean SetProcessAffinityMask(HANDLE hProcess, ULONG_PTR dwProcessAffinityMask);
/**
* Retrieves the termination status of the specified process.
*
* @param hProcess
* A handle to the process.
* @param lpExitCode
* A pointer to a variable to receive the process termination status.
* @return If the function succeeds, the return value is nonzero.
*
* If the function fails, the return value is zero. To get extended
* error information, call GetLastError.
*/
boolean GetExitCodeProcess(HANDLE hProcess, IntByReference lpExitCode);
/**
* Terminates the specified process and all of its threads.
*
* @param hProcess
* A handle to the process to be terminated.
* @param uExitCode
* The exit code to be used by the process and threads terminated
* as a result of this call.
* @return If the function succeeds, the return value is nonzero.
*
* If the function fails, the return value is zero. To get extended
* error information, call GetLastError.
*/
boolean TerminateProcess(HANDLE hProcess, int uExitCode);
/**
* The GetLastError function retrieves the calling thread's last-error code
* value. The last-error code is maintained on a per-thread basis. Multiple
* threads do not overwrite each other's last-error code.
*
* @return The return value is the calling thread's last-error code value.
*/
int GetLastError();
/**
* The SetLastError function sets the last-error code for the calling
* thread.
*
* @param dwErrCode
* Last-error code for the thread.
*/
void SetLastError(int dwErrCode);
/**
* Determines whether a disk drive is a removable, fixed, CD-ROM, RAM
* disk, or network drive.
*
* @param lpRootPathName
* Pointer to a null-terminated string that specifies the root
* directory of the disk to return information about. A trailing
* backslash is required. If this parameter is NULL, the function
* uses the root of the current directory.
* @return The return value specifies the type of drive.
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364939(v=vs.85).aspx">GetDriveType</a>
*/
int GetDriveType(String lpRootPathName);
/**
* The FormatMessage function formats a message string. The function
* requires a message definition as input. The message definition can come
* from a buffer passed into the function. It can come from a message table
* resource in an already-loaded module. Or the caller can ask the function
* to search the system's message table resource(s) for the message
* definition. The function finds the message definition in a message table
* resource based on a message identifier and a language identifier. The
* function copies the formatted message text to an output buffer,
* processing any embedded insert sequences if requested.
*
* @param dwFlags
* Formatting options, and how to interpret the lpSource
* parameter. The low-order byte of dwFlags specifies how the
* function handles line breaks in the output buffer. The
* low-order byte can also specify the maximum width of a
* formatted output line.
* <p>
* This version of the function assumes
* FORMAT_MESSAGE_ALLOCATE_BUFFER is set.</p>
* @param lpSource
* Location of the message definition.
* @param dwMessageId
* Message identifier for the requested message.
* @param dwLanguageId
* Language identifier for the requested message.
* @param lpBuffer
* Pointer to a pointer that receives the allocated buffer in
* which the null-terminated string that specifies the formatted
* message is written.
* @param nSize
* This parameter specifies the minimum number of TCHARs to
* allocate for an output buffer.
* @param va_list
* Pointer to an array of values that are used as insert values
* in the formatted message.
* @return If the function succeeds, the return value is the number of
* TCHARs stored in the output buffer, excluding the terminating
* null character. If the function fails, the return value is zero.
* To get extended error information, call GetLastError.
*/
int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId,
int dwLanguageId, PointerByReference lpBuffer, int nSize,
Pointer va_list);
/**
* The CreateFile function creates or opens a file, file stream, directory,
* physical disk, volume, console buffer, tape drive, communications
* resource, mailslot, or named pipe. The function returns a handle that can
* be used to access an object.
*
* @param lpFileName
* A pointer to a null-terminated string that specifies the name
* of an object to create or open.
* @param dwDesiredAccess
* The access to the object, which can be read, write, or both.
* @param dwShareMode
* The sharing mode of an object, which can be read, write, both,
* or none.
* @param lpSecurityAttributes
* A pointer to a SECURITY_ATTRIBUTES structure that determines
* whether or not the returned handle can be inherited by child
* processes. If lpSecurityAttributes is NULL, the handle cannot
* be inherited.
* @param dwCreationDisposition
* An action to take on files that exist and do not exist.
* @param dwFlagsAndAttributes
* The file attributes and flags.
* @param hTemplateFile
* Handle to a template file with the GENERIC_READ access right.
* The template file supplies file attributes and extended
* attributes for the file that is being created. This parameter
* can be NULL.
* @return If the function succeeds, the return value is an open handle to a
* specified file. If a specified file exists before the function
* call and dwCreationDisposition is CREATE_ALWAYS or OPEN_ALWAYS, a
* call to GetLastError returns ERROR_ALREADY_EXISTS, even when the
* function succeeds. If a file does not exist before the call,
* GetLastError returns 0 (zero). If the function fails, the return
* value is INVALID_HANDLE_VALUE. To get extended error information,
* call GetLastError.
*/
HANDLE CreateFile(String lpFileName, int dwDesiredAccess, int dwShareMode,
WinBase.SECURITY_ATTRIBUTES lpSecurityAttributes,
int dwCreationDisposition, int dwFlagsAndAttributes,
HANDLE hTemplateFile);
/**
* Copies an existing file to a new file.
*
* @param lpExistingFileName
* The name of an existing file.
*
* The name is limited to MAX_PATH characters. To extend this
* limit to 32,767 wide characters, prepend "\\?\" to the path.
* For more information, see Naming a File.
*
* If lpExistingFileName does not exist, CopyFile fails, and
* GetLastError returns ERROR_FILE_NOT_FOUND.
*
* @param lpNewFileName
* The name of the new file.
*
* The name is limited to MAX_PATH characters. To extend this
* limit to 32,767 wide characters, prepend "\\?\" to the path.
* For more information, see Naming a File.
*
* @param bFailIfExists
* If this parameter is TRUE and the new file specified by
* lpNewFileName already exists, the function fails. If this
* parameter is FALSE and the new file already exists, the
* function overwrites the existing file and succeeds.
*
* @return If the function succeeds, the return value is nonzero. If the
* function fails, the return value is zero. To get extended error
* information, call GetLastError.
*/
boolean CopyFile(String lpExistingFileName, String lpNewFileName,
boolean bFailIfExists);
/**
* Moves an existing file or a directory, including its children.
*
* @param lpExistingFileName
* The current name of the file or directory on the local
* computer.
*
* The name is limited to MAX_PATH characters. To extend this
* limit to 32,767 wide characters, prepend "\\?\" to the path.
* For more information, see Naming a File.
* @param lpNewFileName
* The new name for the file or directory. The new name must not
* already exist. A new file may be on a different file system or
* drive. A new directory must be on the same drive.
*
* The name is limited to MAX_PATH characters. To extend this
* limit to 32,767 wide characters, prepend "\\?\" to the path.
* For more information, see Naming a File.
* @return true, if successful If the function succeeds, the return value is
* nonzero.
*
* If the function fails, the return value is zero. To get extended
* error information, call GetLastError.
*/
boolean MoveFile(String lpExistingFileName, String lpNewFileName);
/**
* Moves an existing file or directory, including its children, with various
* move options.
*
* @param lpExistingFileName
* The current name of the file or directory on the local
* computer.
*
* If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT, the file
* cannot exist on a remote share, because delayed operations are
* performed before the network is available.
*
* The name is limited to MAX_PATH characters. To extend this
* limit to 32,767 wide characters, prepend "\\?\" to the path.
* For more information, see Naming a File
*
* Windows 2000: If you prepend the file name with "\\?\", you
* cannot also specify the MOVEFILE_DELAY_UNTIL_REBOOT flag for
* dwFlags.
* @param lpNewFileName
* The new name of the file or directory on the local computer.
*
* When moving a file, the destination can be on a different file
* system or volume. If the destination is on another drive, you
* must set the MOVEFILE_COPY_ALLOWED flag in dwFlags.
*
* When moving a directory, the destination must be on the same
* drive.
*
* If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT and
* lpNewFileName is NULL, MoveFileEx registers the
* lpExistingFileName file to be deleted when the system
* restarts. If lpExistingFileName refers to a directory, the
* system removes the directory at restart only if the directory
* is empty.
* @param dwFlags
* This parameter can be one or more of the following values.
* @return true, if successful If the function succeeds, the return value is
* nonzero.
*
* If the function fails, the return value is zero. To get extended
* error information, call GetLastError.
*/
boolean MoveFileEx(String lpExistingFileName, String lpNewFileName,
DWORD dwFlags);
/**
* The CreateDirectory function creates a new directory. If the underlying
* file system supports security on files and directories, the function
* applies a specified security descriptor to the new directory.
*
* @param lpPathName
* Pointer to a null-terminated string that specifies the path of
* the directory to be created.
* @param lpSecurityAttributes
* Pointer to a SECURITY_ATTRIBUTES structure. The
* lpSecurityDescriptor member of the structure specifies a
* security descriptor for the new directory. If
* lpSecurityAttributes is NULL, the directory gets a default
* security descriptor.
* @return If the function succeeds, the return value is nonzero. If the
* function fails, the return value is zero. To get extended error
* information, call GetLastError.
*/
boolean CreateDirectory(String lpPathName,
WinBase.SECURITY_ATTRIBUTES lpSecurityAttributes);
/**
* Creates an input/output (I/O) completion port and associates it with a
* specified file handle, or creates an I/O completion port that is not yet
* associated with a file handle, allowing association at a later time.
*
* @param FileHandle
* An open file handle or INVALID_HANDLE_VALUE.
* @param ExistingCompletionPort
* A handle to an existing I/O completion port or NULL.
* @param CompletionKey
* The per-handle user-defined completion key that is included in
* every I/O completion packet for the specified file handle.
* @param NumberOfConcurrentThreads
* The maximum number of threads that the operating system can
* allow to concurrently process I/O completion packets for the
* I/O completion port.
* @return If the function succeeds, the return value is the handle to an
* I/O completion port: If the ExistingCompletionPort parameter was
* NULL, the return value is a new handle. If the
* ExistingCompletionPort parameter was a valid I/O completion port
* handle, the return value is that same handle. If the FileHandle
* parameter was a valid handle, that file handle is now associated
* with the returned I/O completion port. If the function fails, the
* return value is NULL. To get extended error information, call the
* GetLastError function.
*/
HANDLE CreateIoCompletionPort(HANDLE FileHandle,
HANDLE ExistingCompletionPort, Pointer CompletionKey,
int NumberOfConcurrentThreads);
/**
* Attempts to dequeue an I/O completion packet from the specified I/O
* completion port. If there is no completion packet queued, the function
* waits for a pending I/O operation associated with the completion port to
* complete.
*
* @param CompletionPort
* A handle to the completion port.
* @param lpNumberOfBytes
* A pointer to a variable that receives the number of bytes
* transferred during an I/O operation that has completed.
* @param lpCompletionKey
* A pointer to a variable that receives the completion key value
* associated with the file handle whose I/O operation has
* completed.
* @param lpOverlapped
* A pointer to a variable that receives the address of the
* OVERLAPPED structure that was specified when the completed I/O
* operation was started.
* @param dwMilliseconds
* The number of milliseconds that the caller is willing to wait
* for a completion packet to appear at the completion port.
* @return Returns nonzero (TRUE) if successful or zero (FALSE) otherwise.
*/
boolean GetQueuedCompletionStatus(HANDLE CompletionPort,
IntByReference lpNumberOfBytes,
ULONG_PTRByReference lpCompletionKey,
PointerByReference lpOverlapped, int dwMilliseconds);
/**
* Posts an I/O completion packet to an I/O completion port.
*
* @param CompletionPort
* A handle to an I/O completion port to which the I/O completion
* packet is to be posted.
* @param dwNumberOfBytesTransferred
* The value to be returned through the
* lpNumberOfBytesTransferred parameter of the
* GetQueuedCompletionStatus function.
* @param dwCompletionKey
* The value to be returned through the lpCompletionKey parameter
* of the GetQueuedCompletionStatus function.
* @param lpOverlapped
* The value to be returned through the lpOverlapped parameter of
* the GetQueuedCompletionStatus function.
* @return If the function succeeds, the return value is nonzero. If the
* function fails, the return value is zero. To get extended error
* information, call GetLastError .
*/
boolean PostQueuedCompletionStatus(HANDLE CompletionPort,
int dwNumberOfBytesTransferred, Pointer dwCompletionKey,
WinBase.OVERLAPPED lpOverlapped);
/**
* Waits until the specified object is in the signaled state or the time-out
* interval elapses. To enter an alertable wait state, use the
* WaitForSingleObjectEx function. To wait for multiple objects, use the
* WaitForMultipleObjects.
*
* @param hHandle
* A handle to the object. For a list of the object types whose
* handles can be specified, see the following Remarks section.
* If this handle is closed while the wait is still pending, the
* function's behavior is undefined. The handle must have the
* SYNCHRONIZE access right. For more information, see Standard
* Access Rights.
* @param dwMilliseconds
* The time-out interval, in milliseconds. If a nonzero value is
* specified, the function waits until the object is signaled or
* the interval elapses. If dwMilliseconds is zero, the function
* does not enter a wait state if the object is not signaled; it
* always returns immediately. If dwMilliseconds is INFINITE, the
* function will return only when the object is signaled.
* @return If the function succeeds, the return value indicates the event
* that caused the function to return.
*/
int WaitForSingleObject(HANDLE hHandle, int dwMilliseconds);
/**
* Waits until one or all of the specified objects are in the signaled state
* or the time-out interval elapses. To enter an alertable wait state, use
* the WaitForMultipleObjectsEx function.
*
* @param nCount
* The number of object handles in the array pointed to by
* lpHandles. The maximum number of object handles is
* MAXIMUM_WAIT_OBJECTS.
* @param hHandle
* An array of object handles. For a list of the object types
* whose handles can be specified, see the following Remarks
* section. The array can contain handles to objects of different
* types. It may not contain multiple copies of the same handle.
* If one of these handles is closed while the wait is still
* pending, the function's behavior is undefined. The handles
* must have the SYNCHRONIZE access right. For more information,
* see Standard Access Rights.
* @param bWaitAll
* If this parameter is TRUE, the function returns when the state
* of all objects in the lpHandles array is signaled. If FALSE,
* the function returns when the state of any one of the objects
* is set to signaled. In the latter case, the return value
* indicates the object whose state caused the function to
* return.
* @param dwMilliseconds
* The time-out interval, in milliseconds. If a nonzero value is
* specified, the function waits until the specified objects are
* signaled or the interval elapses. If dwMilliseconds is zero,
* the function does not enter a wait state if the specified
* objects are not signaled; it always returns immediately. If
* dwMilliseconds is INFINITE, the function will return only when
* the specified objects are signaled.
* @return If the function succeeds, the return value indicates the event
* that caused the function to return.
*/
int WaitForMultipleObjects(int nCount, HANDLE[] hHandle, boolean bWaitAll,
int dwMilliseconds);
/**
* The DuplicateHandle function duplicates an object handle.
*
* @param hSourceProcessHandle
* Handle to the process with the handle to duplicate. The handle
* must have the PROCESS_DUP_HANDLE access right.
* @param hSourceHandle
* Handle to duplicate. This is an open object handle that is
* valid in the context of the source process.
* @param hTargetProcessHandle
* Handle to the process that is to receive the duplicated
* handle. The handle must have the PROCESS_DUP_HANDLE access
* right.
* @param lpTargetHandle
* Pointer to a variable that receives the duplicate handle. This
* handle value is valid in the context of the target process. If
* hSourceHandle is a pseudo handle returned by GetCurrentProcess
* or GetCurrentThread, DuplicateHandle converts it to a real
* handle to a process or thread, respectively.
* @param dwDesiredAccess
* Access requested for the new handle.
* @param bInheritHandle
* Indicates whether the handle is inheritable.
* @param dwOptions
* Optional actions.
* @return If the function succeeds, the return value is nonzero. If the
* function fails, the return value is zero. To get extended error
* information, call GetLastError.
*/
boolean DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle,
HANDLE hTargetProcessHandle, HANDLEByReference lpTargetHandle,
int dwDesiredAccess, boolean bInheritHandle, int dwOptions);
/**
* Closes an open object handle.
*
* @param hObject
* Handle to an open object. This parameter can be a pseudo
* handle or INVALID_HANDLE_VALUE.
* @return If the function succeeds, the return value is nonzero. If the
* function fails, the return value is zero. To get extended error
* information, call {@code GetLastError}.
* @see <A HREF="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx">CloseHandle</A>
*/
boolean CloseHandle(HANDLE hObject);
/**
* Retrieves information that describes the changes within the specified
* directory. The function does not report changes to the specified
* directory itself. Note: there's no ReadDirectoryChangesA.
*
* @param directory
* A handle to the directory to be monitored. This directory must
* be opened with the FILE_LIST_DIRECTORY access right.
* @param info
* A pointer to the DWORD-aligned formatted buffer in which the
* read results are to be returned.
* @param length
* The size of the buffer that is pointed to by the lpBuffer
* parameter, in bytes.
* @param watchSubtree
* If this parameter is TRUE, the function monitors the directory
* tree rooted at the specified directory. If this parameter is
* FALSE, the function monitors only the directory specified by
* the hDirectory parameter.
* @param notifyFilter
* The filter criteria that the function checks to determine if
* the wait operation has completed.
* @param bytesReturned
* For synchronous calls, this parameter receives the number of
* bytes transferred into the lpBuffer parameter. For
* asynchronous calls, this parameter is undefined. You must use
* an asynchronous notification technique to retrieve the number
* of bytes transferred.
* @param overlapped
* A pointer to an OVERLAPPED structure that supplies data to be
* used during asynchronous operation. Otherwise, this value is
* NULL. The Offset and OffsetHigh members of this structure are
* not used.
* @param completionRoutine
* A pointer to a completion routine to be called when the
* operation has been completed or canceled and the calling
* thread is in an alertable wait state.
* @return If the function succeeds, the return value is nonzero. For
* synchronous calls, this means that the operation succeeded. For
* asynchronous calls, this indicates that the operation was
* successfully queued. If the function fails, the return value is
* zero. To get extended error information, call GetLastError. If
* the network redirector or the target file system does not support
* this operation, the function fails with ERROR_INVALID_FUNCTION.
*/
public boolean ReadDirectoryChangesW(HANDLE directory,
WinNT.FILE_NOTIFY_INFORMATION info, int length,
boolean watchSubtree, int notifyFilter,
IntByReference bytesReturned, WinBase.OVERLAPPED overlapped,
OVERLAPPED_COMPLETION_ROUTINE completionRoutine);
/**
* Retrieves the short path form of the specified path.
*
* @param lpszLongPath
* The path string.
* @param lpdzShortPath
* A pointer to a buffer to receive the null-terminated short
* form of the path that lpszLongPath specifies.
* @param cchBuffer
* The size of the buffer that lpszShortPath points to, in
* TCHARs.
* @return If the function succeeds, the return value is the length, in
* TCHARs, of the string that is copied to lpszShortPath, not
* including the terminating null character. If the lpszShortPath
* buffer is too small to contain the path, the return value is the
* size of the buffer, in TCHARs, that is required to hold the path
* and the terminating null character. If the function fails for any
* other reason, the return value is zero. To get extended error
* information, call GetLastError.
*/
int GetShortPathName(String lpszLongPath, char[] lpdzShortPath,
int cchBuffer);
/**
* The LocalAlloc function allocates the specified number of bytes from the
* heap. Windows memory management does not provide a separate local heap
* and global heap.
*
* @param uFlags
* Memory allocation attributes. The default is the LMEM_FIXED
* value.
* @param uBytes
* Number of bytes to allocate. If this parameter is zero and the
* uFlags parameter specifies LMEM_MOVEABLE, the function returns
* a handle to a memory object that is marked as discarded.
* @return If the function succeeds, the return value is a handle to the
* newly allocated memory object. If the function fails, the return
* value is NULL. To get extended error information, call
* GetLastError.
*/
Pointer LocalAlloc(int /* UINT */uFlags, int /* SIZE_T */uBytes);
/**
* Writes data to the specified file or input/output (I/O) device.
*
* @param hFile
* A handle to the file or I/O device (for example, a file, file
* stream, physical disk, volume, console buffer, tape drive,
* socket, communications resource, mailslot, or pipe).
* @param lpBuffer
* A pointer to the buffer containing the data to be written to
* the file or device.
* @param nNumberOfBytesToWrite
* The number of bytes to be written to the file or device.
* @param lpNumberOfBytesWritten
* A pointer to the variable that receives the number of bytes
* written when using a synchronous hFile parameter.
* @param lpOverlapped
* A pointer to an OVERLAPPED structure is required if the hFile
* parameter was opened with FILE_FLAG_OVERLAPPED, otherwise this
* parameter can be NULL.
* @return If the function succeeds, the return value is nonzero (TRUE). If
* the function fails, or is completing asynchronously, the return
* value is zero (FALSE). To get extended error information, call
* the GetLastError function.
*/
boolean WriteFile(HANDLE hFile, byte[] lpBuffer, int nNumberOfBytesToWrite,
IntByReference lpNumberOfBytesWritten,
WinBase.OVERLAPPED lpOverlapped);
/**
* Flushes the buffers of a specified file and causes all buffered data
* to be written to a file.
* @param hFile A handle to the open file. If a handle to a communications
* device, the function only flushes the transmit buffer. If a handle to the
* server end of a named pipe, the function does not return until the client
* has read all buffered data from the pipe.
* @return {@code true} if successful, {@code false} otherwise.
* To get extended error information, call {@link #GetLastError()}.
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364439(v=vs.85).aspx">FlushFileBuffers documentation</a>
*/
boolean FlushFileBuffers(HANDLE hFile);
/**
* Creates or opens a named or unnamed event object.
*
* @param lpEventAttributes
* A pointer to a SECURITY_ATTRIBUTES structure. If this
* parameter is NULL, the handle cannot be inherited by child
* processes.
* @param bManualReset
* If this parameter is TRUE, the function creates a manual-reset
* event object, which requires the use of the ResetEvent
* function to set the event state to nonsignaled. If this
* parameter is FALSE, the function creates an auto-reset event
* object, and system automatically resets the event state to
* nonsignaled after a single waiting thread has been released.
* @param bInitialState
* If this parameter is TRUE, the initial state of the event
* object is signaled; otherwise, it is nonsignaled.
* @param lpName
* The name of the event object. The name is limited to MAX_PATH
* characters. Name comparison is case sensitive.
* @return If the function succeeds, the return value is a handle to the
* event object. If the named event object existed before the
* function call, the function returns a handle to the existing
* object and GetLastError returns ERROR_ALREADY_EXISTS. If the
* function fails, the return value is NULL. To get extended error
* information, call GetLastError.
*/
HANDLE CreateEvent(WinBase.SECURITY_ATTRIBUTES lpEventAttributes,
boolean bManualReset, boolean bInitialState, String lpName);
/**
* Opens an existing named event object.
*