winsafe 0.0.27

Windows API and GUI in safe, idiomatic Rust.
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
#![allow(non_camel_case_types, non_snake_case)]

use std::marker::PhantomData;

use crate::co;
use crate::decl::*;
use crate::kernel::privs::*;

/// [`ACL`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-acl)
/// struct.
#[repr(C)]
#[derive(Default)]
pub struct ACL {
	pub AclRevision: u8,
	pub Sbz1: u8,
	pub AclSize: u16,
	pub AceCount: u16,
	pub Sbz2: u16,
}

/// [`ACTCTX`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-actctxw)
/// struct.
#[repr(C)]
pub struct ACTCTX<'a, 'b, 'c, 'd> {
	cbSize: u32,
	pub dwFlags: co::ACTCTX_FLAG,
	lpSource: *mut u16,
	pub wProcessorArchitecture: co::PROCESSOR_ARCHITECTURE,
	pub wLangId: LANGID,
	lpAssemblyDirectory: *mut u16,
	lpResourceName: *mut u16,
	lpApplicationName: *mut u16,
	pub hModule: HINSTANCE,

	_lpSource: PhantomData<&'a mut u16>,
	_lpAssemblyDirectory: PhantomData<&'b mut u16>,
	_lpResourceName: PhantomData<&'c mut u16>,
	_lpApplicationName: PhantomData<&'d mut u16>,
}

impl_default!(ACTCTX, cbSize, 'a, 'b, 'c, 'd);

impl<'a, 'b, 'c, 'd> ACTCTX<'a, 'b, 'c, 'd> {
	pub_fn_string_ptr_get_set!('a, lpSource, set_lpSource);
	pub_fn_string_ptr_get_set!('b, lpAssemblyDirectory, set_lpAssemblyDirectory);
	pub_fn_string_ptr_get_set!('c, lpResourceName, set_lpResourceName);
	pub_fn_string_ptr_get_set!('d, lpApplicationName, set_lpApplicationName);
}

/// [`BY_HANDLE_FILE_INFORMATION`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information)
/// struct.
#[repr(C)]
#[derive(Default)]
pub struct BY_HANDLE_FILE_INFORMATION {
	pub dwFileAttributes: co::FILE_ATTRIBUTE,
	pub ftCreationTime: FILETIME,
	pub ftLastAccessTime: FILETIME,
	pub ftLastWriteTime: FILETIME,
	pub dwVolumeSerialNumber: u32,
	nFileSizeHigh: u32,
	nFileSizeLow: u32,
	pub nNumberOfLinks: u32,
	nFileIndexHigh: u32,
	nFileIndexLow: u32,
}

impl BY_HANDLE_FILE_INFORMATION {
	/// Returns the nFileSizeHigh and nFileSizeLow fields.
	#[must_use]
	pub const fn nFileSize(&self) -> u64 {
		MAKEQWORD(self.nFileSizeLow, self.nFileSizeHigh)
	}

	/// Sets the nFileSizeHigh and nFileSizeLow fields.
	pub const fn set_nFileSize(&mut self, val: u64) {
		self.nFileSizeHigh = HIDWORD(val);
		self.nFileSizeLow = LODWORD(val);
	}

	/// Returns the nFileIndexHigh and nFileIndexLow fields.
	#[must_use]
	pub const fn nFileIndex(&self) -> u64 {
		MAKEQWORD(self.nFileIndexLow, self.nFileIndexHigh)
	}

	/// Sets the nFileIndexHigh and nFileIndexLow fields.
	pub const fn set_nFileIndex(&mut self, val: u64) {
		self.nFileIndexHigh = HIDWORD(val);
		self.nFileIndexLow = LODWORD(val);
	}
}

/// [`CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-claim_security_attribute_fqbn_value)
/// struct.
#[repr(C)]
pub struct CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE<'a> {
	pub Version: u64,
	Name: *mut u16,

	_Name: PhantomData<&'a mut u16>,
}

impl_default!(CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE, 'a);

impl<'a> CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE<'a> {
	pub_fn_string_ptr_get_set!('a, Name, set_Name);
}

/// [`CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-claim_security_attribute_octet_string_value)
/// struct.
#[repr(C)]
pub struct CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE<'a> {
	pValue: *mut u8,
	ValueLength: u32,

	_pValue: PhantomData<&'a mut ()>,
}

impl_default!(CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE, 'a);

impl<'a> CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE<'a> {
	pub_fn_array_buf_get_set!('a, pValue, set_pValue, ValueLength, u8);
}

/// [`CLAIM_SECURITY_ATTRIBUTE_V1`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-claim_security_attribute_v1)
/// struct.
#[repr(C)]
pub struct CLAIM_SECURITY_ATTRIBUTE_V1<'a, 'b> {
	Name: *mut u16,
	ValueType: co::CLAIM_SECURITY_ATTRIBUTE_TYPE,
	Reserved: u16,
	Flags: u32,
	ValueCount: u32,
	Values: CLAIM_SECURITY_ATTRIBUTE_V1_union0<'b>,

	_Name: PhantomData<&'a mut u16>,
}

#[repr(C)]
union CLAIM_SECURITY_ATTRIBUTE_V1_union0<'a> {
	pInt64: *mut i64, // pointers because these are all arrays with ValueCount items
	pUint64: *mut u64,
	ppString: *mut *mut u16,
	pFqbn: *mut CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE<'a>,
	pOctetString: *mut CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE<'a>,
}

impl_default!(CLAIM_SECURITY_ATTRIBUTE_V1, 'a, 'b);

impl<'a, 'b> CLAIM_SECURITY_ATTRIBUTE_V1<'a, 'b> {
	pub_fn_string_ptr_get_set!('a, Name, set_Name);

	/// Returns the low-word part of `Flags`.
	#[must_use]
	pub const fn FlagsLo(&self) -> co::CLAIM_SECURITY_ATTRIBUTE {
		unsafe { co::CLAIM_SECURITY_ATTRIBUTE::from_raw(LOWORD(self.Flags)) }
	}

	/// Sets the low-word part of `Flags`.
	pub const fn set_FlagsLo(&mut self, claim: co::CLAIM_SECURITY_ATTRIBUTE) {
		self.Flags = MAKEDWORD(claim.raw(), self.FlagsHi());
	}

	/// Returns the high-word part of `Flags`.
	#[must_use]
	pub const fn FlagsHi(&self) -> u16 {
		HIWORD(self.Flags)
	}

	/// Sets the high-word part of `Flags`.
	pub const fn set_FlagsHi(&mut self, flags: u16) {
		self.Flags = MAKEDWORD(self.FlagsLo().raw(), flags);
	}

	/// Returns the `Values` field.
	///
	/// # Panics
	///
	/// Panics if `ValueType` field is invalid.
	#[must_use]
	pub fn Values(&self) -> ClaimSecurityAttr<'_> {
		unsafe {
			match self.ValueType {
				co::CLAIM_SECURITY_ATTRIBUTE_TYPE::INT64 => ClaimSecurityAttr::Int64(
					std::slice::from_raw_parts(self.Values.pInt64, self.ValueCount as _),
				),
				co::CLAIM_SECURITY_ATTRIBUTE_TYPE::UINT64 => ClaimSecurityAttr::Uint64(
					std::slice::from_raw_parts(self.Values.pUint64, self.ValueCount as _),
				),
				co::CLAIM_SECURITY_ATTRIBUTE_TYPE::STRING => ClaimSecurityAttr::String(
					std::slice::from_raw_parts(self.Values.ppString, self.ValueCount as _)
						.iter()
						.map(|str_ptr| WString::from_wchars_nullt(*str_ptr).to_string())
						.collect(),
				),
				co::CLAIM_SECURITY_ATTRIBUTE_TYPE::FQBN => ClaimSecurityAttr::Fbqn(
					std::slice::from_raw_parts(self.Values.pFqbn, self.ValueCount as _),
				),
				co::CLAIM_SECURITY_ATTRIBUTE_TYPE::OCTET_STRING => ClaimSecurityAttr::OctetString(
					std::slice::from_raw_parts(self.Values.pOctetString, self.ValueCount as _),
				),
				_ => panic!("Invalid ValueType."),
			}
		}
	}
}

/// [`CONSOLE_READCONSOLE_CONTROL`](https://learn.microsoft.com/en-us/windows/console/console-readconsole-control)
/// struct.
#[repr(C)]
#[derive(Default)]
pub struct CONSOLE_READCONSOLE_CONTROL {
	pub nLength: u32,
	pub nInitialChars: u32,
	pub dwCtrlWakeupMask: u32,
	pub dwControlKeyState: u32,
}

/// [`DEV_BROADCAST_HDR`](https://learn.microsoft.com/en-us/windows/win32/api/dbt/ns-dbt-dev_broadcast_hdr)
/// struct.
#[repr(C)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub struct DEV_BROADCAST_HDR {
	pub dbch_size: u32, // used by SvcCtlDeviceEvent (advapi) and wm::DeviceChange (user)
	pub dbch_devicetype: co::DBT_DEVTYP,
	dbch_reserved: u32,
}

/// [`DISK_SPACE_INFORMATION`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-disk_space_information)
/// struct.
#[repr(C)]
#[derive(Default, Clone, PartialEq, Eq)]
pub struct DISK_SPACE_INFORMATION {
	pub ActualTotalAllocationUnits: u64,
	pub ActualAvailableAllocationUnits: u64,
	pub ActualPoolUnavailableAllocationUnits: u64,
	pub CallerTotalAllocationUnits: u64,
	pub CallerAvailableAllocationUnits: u64,
	pub CallerPoolUnavailableAllocationUnits: u64,
	pub UsedAllocationUnits: u64,
	pub TotalReservedAllocationUnits: u64,
	pub VolumeStorageReserveAllocationUnits: u64,
	pub AvailableCommittedAllocationUnits: u64,
	pub PoolAvailableAllocationUnits: u64,
	pub SectorsPerAllocationUnit: u32,
	pub BytesPerSector: u32,
}

/// [`FILETIME`](https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime)
/// struct.
///
/// Can be converted to [`SYSTEMTIME`](crate::SYSTEMTIME) with
/// [`FileTimeToSystemTime`](crate::FileTimeToSystemTime) function.
#[repr(C)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FILETIME {
	pub dwLowDateTime: u32,
	pub dwHighDateTime: u32,
}

impl From<u64> for FILETIME {
	fn from(v: u64) -> Self {
		Self {
			dwLowDateTime: LODWORD(v),
			dwHighDateTime: HIDWORD(v),
		}
	}
}

impl From<FILETIME> for u64 {
	fn from(v: FILETIME) -> Self {
		MAKEQWORD(v.dwLowDateTime, v.dwHighDateTime)
	}
}

impl FILETIME {
	/// Returns a new `FILETIME` with the milliseconds difference.
	#[must_use]
	pub const fn add_ms(self, ms: i64) -> Self {
		let self64 = MAKEQWORD(self.dwLowDateTime, self.dwHighDateTime) as i64;
		let new_self64 = self64 + (ms * 10_000);
		Self {
			dwLowDateTime: LODWORD(new_self64 as _),
			dwHighDateTime: HIDWORD(new_self64 as _),
		}
	}

	/// Returns a new `FILETIME` with the seconds difference.
	#[must_use]
	pub const fn add_secs(self, secs: i64) -> Self {
		self.add_ms(secs * 1000)
	}

	/// Returns a new `FILETIME` with the minutes difference.
	#[must_use]
	pub const fn add_mins(self, mins: i64) -> Self {
		self.add_secs(mins * 60)
	}

	/// Returns a new `FILETIME` with the hours difference.
	#[must_use]
	pub const fn add_hours(self, hours: i64) -> Self {
		self.add_mins(hours * 60)
	}

	/// Returns a new `FILETIME` with the days difference.
	#[must_use]
	pub const fn add_days(self, days: i64) -> Self {
		self.add_hours(days * 24)
	}
}

/// [`GUID`](https://learn.microsoft.com/en-us/windows/win32/api/guiddef/ns-guiddef-guid)
/// struct.
///
/// The [`Default`](std::default::Default) implementation returns `GUID::NULL`
/// (all zeros). To create a new random `GUID`, use
/// [`CoCreateGuid`](crate::CoCreateGuid).
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GUID {
	data1: u32,
	data2: u16,
	data3: u16,
	data4: u64,
}

impl std::fmt::Display for GUID {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		write!(
			f,
			"{:08x}-{:04x}-{:04x}-{:04x}-{:012x}",
			self.data1,
			self.data2,
			self.data3,
			self.data4.swap_bytes() >> 48,
			self.data4.swap_bytes() & 0x0000_ffff_ffff_ffff,
		)
	}
}
impl std::fmt::Debug for GUID {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		std::fmt::Display::fmt(self, f)
	}
}

impl GUID {
	/// The null `GUID`, with all zeros.
	pub const NULL: Self = Self::from_str("00000000-0000-0000-0000-000000000000");

	/// Creates a new `GUID` from a representative hex string, which can be
	/// copied straight from standard `GUID` declarations.
	///
	/// # Panics
	///
	/// Panics if the string has an invalid format.
	///
	/// # Examples
	///
	/// ```no_run
	/// use winsafe::{self as w, prelude::*};
	///
	/// let g = w::GUID::from_str("43826d1e-e718-42ee-bc55-a1e261c37bfe");
	/// ```
	#[must_use]
	pub const fn from_str(guid_str: &str) -> Self {
		if guid_str.len() != 36 {
			panic!("Bad number of GUID chars.");
		}

		let chs = guid_str.as_bytes();
		let p1 =
			Self::parse_block([chs[0], chs[1], chs[2], chs[3], chs[4], chs[5], chs[6], chs[7]]);
		let p2 = Self::parse_block([chs[9], chs[10], chs[11], chs[12]]);
		let p3 = Self::parse_block([chs[14], chs[15], chs[16], chs[17]]);
		let p4 = Self::parse_block([chs[19], chs[20], chs[21], chs[22]]);
		let p5 = Self::parse_block([
			chs[24], chs[25], chs[26], chs[27], chs[28], chs[29], chs[30], chs[31], chs[32],
			chs[33], chs[34], chs[35],
		]);

		Self {
			data1: p1 as _,
			data2: p2 as _,
			data3: p3 as _,
			data4: ((p4 << 48) | p5).swap_bytes(),
		}
	}

	#[must_use]
	const fn parse_block<const N: usize>(chars: [u8; N]) -> u64 {
		let mut res: u64 = 0;
		let mut idx: usize = 0;
		while idx < N {
			let ch = chars[idx];
			if !Self::valid_char(ch) {
				panic!("Bad GUID char.");
			}
			res += Self::char_to_num(ch) * 16_u64.pow((N - idx - 1) as _);
			idx += 1;
		}
		res
	}

	#[must_use]
	const fn valid_char(ch: u8) -> bool {
		(ch >= 48 && ch <= 57) // 0-9
			|| (ch >= 65 && ch <= 70) // A-F
			|| (ch >= 97 && ch <= 102) // a-f
	}

	#[must_use]
	const fn char_to_num(ch: u8) -> u64 {
		if ch >= 48 && ch <= 57 {
			ch as u64 - 48
		} else if ch >= 65 && ch <= 70 {
			ch as u64 - 65 + 10
		} else if ch >= 97 && ch <= 102 {
			ch as u64 - 97 + 10
		} else {
			panic!("Bad GUID char in conversion.");
		}
	}
}

/// [`HEAPLIST32`](https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/ns-tlhelp32-heaplist32)
/// struct.
#[repr(C)]
pub struct HEAPLIST32 {
	dwSize: usize,
	pub th32ProcessID: u32,
	pub th32HeapID: usize,
	pub dwFlags: co::HF32,
}

impl_default!(HEAPLIST32, dwSize);

newtype_num! { LANGID: u16;
	/// [`LANGID`](https://learn.microsoft.com/en-us/windows/win32/intl/language-identifiers)
	/// language identifier.
}

impl std::fmt::Debug for LANGID {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		write!(
			f,
			"Primary [{:#04x} {}], Sublang [{:#04x} {}]",
			self.primary_lang_id(),
			self.primary_lang_id(),
			self.sub_lang_id(),
			self.sub_lang_id()
		)
	}
}
impl std::fmt::Display for LANGID {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		std::fmt::Debug::fmt(self, f)
	}
}

impl LANGID {
	/// [`LANGID`](crate::LANGID) composed of
	/// [`LANG::NEUTRAL`](crate::co::LANG::NEUTRAL) and
	/// [`SUBLANG::NEUTRAL`](crate::co::SUBLANG::NEUTRAL).
	pub const NEUTRAL: Self = Self::new(co::LANG::NEUTRAL, co::SUBLANG::NEUTRAL);

	/// [`LANGID`](crate::LANGID) composed of
	/// [`LANG::NEUTRAL`](crate::co::LANG::NEUTRAL) and
	/// [`SUBLANG::SYS_DEFAULT`](crate::co::SUBLANG::SYS_DEFAULT).
	pub const SYSTEM_DEFAULT: Self = Self::new(co::LANG::NEUTRAL, co::SUBLANG::SYS_DEFAULT);

	/// [`LANGID`](crate::LANGID) composed of
	/// [`LANG::NEUTRAL`](crate::co::LANG::NEUTRAL) and
	/// [`SUBLANG::DEFAULT`](crate::co::SUBLANG::DEFAULT).
	pub const USER_DEFAULT: Self = Self::new(co::LANG::NEUTRAL, co::SUBLANG::DEFAULT);

	/// Creates a new `LANGID`. Originally
	/// [`MAKELANGID`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-makelangid)
	/// macro.
	#[must_use]
	pub const fn new(lang: co::LANG, sublang: co::SUBLANG) -> Self {
		Self((sublang.raw() << 10) | lang.raw())
	}

	/// Returns the primary language ID. Originally
	/// [`PRIMARYLANGID`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-primarylangid)
	/// macro.
	#[must_use]
	pub const fn primary_lang_id(self) -> co::LANG {
		unsafe { co::LANG::from_raw(self.0 & 0x3ff) }
	}

	/// Returns the sublanguage ID. Originally
	/// [`SUBLANGID`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-sublangid)
	/// macro.
	#[must_use]
	pub const fn sub_lang_id(self) -> co::SUBLANG {
		unsafe { co::SUBLANG::from_raw(self.0 >> 10) }
	}
}

newtype_num! { LCID: u32;
	/// [`LCID`](https://learn.microsoft.com/en-us/windows/win32/intl/locale-identifiers)
	/// locale identifier.
}

impl LCID {
	/// [`LCID`](crate::LCID) composed of
	/// [`LANGID::SYSTEM_DEFAULT`](crate::LANGID::SYSTEM_DEFAULT) and
	/// [`SORT::DEFAULT`](crate::co::SORT::DEFAULT).
	pub const SYSTEM_DEFAULT: Self = Self::new(LANGID::SYSTEM_DEFAULT, co::SORT::DEFAULT);

	/// [`LCID`](crate::LCID) composed of
	/// [`LANGID::USER_DEFAULT`](crate::LANGID::USER_DEFAULT) and
	/// [`SORT::DEFAULT`](crate::co::SORT::DEFAULT).
	pub const USER_DEFAULT: Self = Self::new(LANGID::USER_DEFAULT, co::SORT::DEFAULT);

	/// Creates a new `LCID`. Originally
	/// [`MAKELCID`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-makelcid)
	/// macro.
	#[must_use]
	pub const fn new(lang_id: LANGID, sort_id: co::SORT) -> Self {
		Self(((sort_id.raw() as u32) << 16) | lang_id.raw() as u32)
	}

	/// Returns the language identifier. Originally
	/// [`LANGIDFROMLCID`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-langidfromlcid)
	/// macro.
	#[must_use]
	pub const fn lang_id(self) -> LANGID {
		unsafe { LANGID::from_raw(self.raw() as _) }
	}

	/// Returns the sort ID. Originally
	/// [`SORTIDFROMLCID`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-sortidfromlcid)
	/// macro.
	#[must_use]
	pub const fn sort_id(self) -> co::SORT {
		unsafe { co::SORT::from_raw(((self.raw() >> 16) & 0xf) as _) }
	}
}

/// [`LUID`](https://learn.microsoft.com/en-us/windows/win32/api/ntdef/ns-ntdef-luid)
/// identifier.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LUID {
	LowPart: u32,
	HighPart: i32,
}

impl std::fmt::Display for LUID {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		write!(f, "LUID lo: {:#04x}, hi: {:#04x}", self.low_part(), self.high_part())
	}
}

impl LUID {
	pub const SYSTEM: Self = Self::from_parts(0x3e7, 0x0);
	pub const ANONYMOUS_LOGON: Self = Self::from_parts(0x3e6, 0x0);
	pub const LOCALSERVICE: Self = Self::from_parts(0x3e5, 0x0);
	pub const NETWORKSERVICE: Self = Self::from_parts(0x3e4, 0x0);
	pub const IUSER: Self = Self::from_parts(0x3e3, 0x0);
	pub const PROTECTED_TO_SYSTEM: Self = Self::from_parts(0x3e2, 0x0);

	/// Creates a new `LUID`.
	#[must_use]
	pub const fn from_parts(low_part: u32, high_part: i32) -> Self {
		Self { LowPart: low_part, HighPart: high_part }
	}

	/// Returns the low part.
	#[must_use]
	pub const fn low_part(&self) -> u32 {
		self.LowPart
	}

	/// Returns the high part.
	#[must_use]
	pub const fn high_part(&self) -> i32 {
		self.HighPart
	}
}

/// [`MEMORY_BASIC_INFORMATION`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-memory_basic_information)
/// struct.
#[repr(C)]
pub struct MEMORY_BASIC_INFORMATION {
	pub BaseAddress: *mut std::ffi::c_void,
	pub AllocationBase: *mut std::ffi::c_void,
	pub AllocationProtect: co::PAGE,
	pub PartitionId: u16,
	pub RegionSize: usize,
	pub State: co::MEM_STATE,
	pub Protect: co::PAGE,
	pub Type: co::MEM_TYPE,
}

impl_default!(MEMORY_BASIC_INFORMATION);

/// [`MODULEENTRY32`](https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/ns-tlhelp32-moduleentry32w)
/// struct.
#[repr(C)]
pub struct MODULEENTRY32 {
	dwSize: u32,
	th32ModuleID: u32,
	pub th32ProcessID: u32,
	pub GlblcntUsage: u32,
	pub ProccntUsage: u32,
	pub modBaseAddr: *mut std::ffi::c_void,
	pub modBaseSize: u32,
	pub hModule: HINSTANCE,
	szModule: [u16; MAX_MODULE_NAME32 + 1],
	szExePath: [u16; MAX_PATH],
}

impl_default!(MODULEENTRY32, dwSize);

impl MODULEENTRY32 {
	pub_fn_string_arr_get_set!(szModule, set_szModule);
	pub_fn_string_arr_get_set!(szExePath, set_szExePath);
}

/// [`MEMORYSTATUSEX`](https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex)
/// struct.
#[repr(C)]
pub struct MEMORYSTATUSEX {
	dwLength: u32,
	pub dwMemoryLoad: u32,
	pub ullTotalPhys: u64,
	pub ullAvailPhys: u64,
	pub ullTotalPageFile: u64,
	pub ullAvailPageFile: u64,
	pub ullTotalVirtual: u64,
	pub ullAvailVirtual: u64,
	pub ullAvailExtendedVirtual: u64,
}

impl_default!(MEMORYSTATUSEX, dwLength);

/// [`OSVERSIONINFOEX`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexw)
/// struct.
#[repr(C)]
pub struct OSVERSIONINFOEX {
	dwOSVersionInfoSize: u32,
	pub dwMajorVersion: u32,
	pub dwMinorVersion: u32,
	pub dwBuildNumber: u32,
	pub dwPlatformId: co::VER_PLATFORM,
	szCSDVersion: [u16; 128],
	pub wServicePackMajor: u16,
	pub wServicePackMinor: u16,
	pub wSuiteMask: co::VER_SUITE,
	pub wProductType: co::VER_NT,
	wReserved: u8,
}

impl_default!(OSVERSIONINFOEX, dwOSVersionInfoSize);

impl OSVERSIONINFOEX {
	pub_fn_string_arr_get_set!(szCSDVersion, set_szCSDVersion);
}

/// [`OVERLAPPED`](https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-overlapped)
/// struct.
#[repr(C)]
pub struct OVERLAPPED {
	pub Internal: usize,
	pub InternalHigh: usize,
	pub Pointer: usize,
	pub hEvent: HEVENT,
}

impl_default!(OVERLAPPED);

/// [`POWERBROADCAST_SETTING`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-powerbroadcast_setting)
/// struct.
///
/// The `Data` field is dynamically allocated.
#[allow(dead_code)] // used by wm::PowerBroadcast in user
#[repr(C)]
pub struct POWERBROADCAST_SETTING {
	pub PowerSetting: co::POWER_SETTING,
	pub DataLength: u32,
	Data: [u8; 1],
}

impl POWERBROADCAST_SETTING {
	/// Returns the `Data` field according to `PowerSetting` identifier.
	///
	/// # Panics
	///
	/// Panics if `PowerSetting` identifier is invalid.
	///
	/// # Safety
	///
	/// Make sure the struct contains the correct size and data described by the
	/// `PowerSetting` identifier.
	#[must_use]
	pub const unsafe fn data(&self) -> PowerSetting {
		unsafe {
			match self.PowerSetting {
				co::POWER_SETTING::ACDC_POWER_SOURCE => {
					PowerSetting::AcDcPowerSource(co::SYSTEM_POWER_CONDITION::from_raw(
						std::slice::from_raw_parts(self.Data.as_ptr() as *const _, 1)[0],
					))
				},
				co::POWER_SETTING::BATTERY_PERCENTAGE_REMAINING => {
					PowerSetting::BatteryPercentageRemaining(
						std::slice::from_raw_parts(self.Data.as_ptr() as *const u32, 1)[0] as _,
					)
				},
				co::POWER_SETTING::CONSOLE_DISPLAY_STATE => {
					PowerSetting::ConsoleDisplayState(co::MONITOR_DISPLAY_STATE::from_raw(
						std::slice::from_raw_parts(self.Data.as_ptr() as *const _, 1)[0],
					))
				},
				co::POWER_SETTING::GLOBAL_USER_PRESENCE => {
					PowerSetting::GlobalUserPresence(co::USER_ACTIVITY_PRESENCE::from_raw(
						std::slice::from_raw_parts(self.Data.as_ptr() as *const _, 1)[0],
					))
				},
				co::POWER_SETTING::IDLE_BACKGROUND_TASK => PowerSetting::IdleBackgroundTask,
				co::POWER_SETTING::MONITOR_POWER_ON => PowerSetting::MonitorPowerOn(
					match std::slice::from_raw_parts(self.Data.as_ptr() as *const u32, 1)[0] {
						0 => false,
						_ => true,
					},
				),
				co::POWER_SETTING::POWER_SAVING_STATUS => PowerSetting::PowerSavingStatus(
					match std::slice::from_raw_parts(self.Data.as_ptr() as *const u32, 1)[0] {
						0 => false,
						_ => true,
					},
				),
				co::POWER_SETTING::POWERSCHEME_PERSONALITY => PowerSetting::PowerSchemePersonality(
					std::slice::from_raw_parts(self.Data.as_ptr() as *const co::POWER_SAVINGS, 1)
						[0],
				),
				co::POWER_SETTING::SESSION_DISPLAY_STATUS => {
					PowerSetting::SessionDisplayStatus(co::MONITOR_DISPLAY_STATE::from_raw(
						std::slice::from_raw_parts(self.Data.as_ptr() as *const _, 1)[0],
					))
				},
				co::POWER_SETTING::SESSION_USER_PRESENCE => {
					PowerSetting::SessionUserPresence(co::USER_ACTIVITY_PRESENCE::from_raw(
						std::slice::from_raw_parts(self.Data.as_ptr() as *const _, 1)[0],
					))
				},
				co::POWER_SETTING::LIDSWITCH_STATE_CHANGE => PowerSetting::LidSwitchStateChange(
					match std::slice::from_raw_parts(self.Data.as_ptr() as *const u8, 1)[0] {
						0 => PowerSettingLid::Closed,
						_ => PowerSettingLid::Opened,
					},
				),
				co::POWER_SETTING::SYSTEM_AWAYMODE => PowerSetting::SystemAwayMode(
					match std::slice::from_raw_parts(self.Data.as_ptr() as *const u8, 1)[0] {
						0 => PowerSettingAwayMode::Exiting,
						_ => PowerSettingAwayMode::Entering,
					},
				),
				_ => panic!("Invalid co::POWER_SETTING."),
			}
		}
	}
}

/// [`PROCESS_HEAP_ENTRY`](https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-process_heap_entry)
/// struct.
#[repr(C)]
pub struct PROCESS_HEAP_ENTRY {
	pub lpData: *mut std::ffi::c_void,
	pub cbData: u32,
	pub cbOverhead: u8,
	pub iRegionIndex: u8,
	pub wFlags: co::PROCESS_HEAP,
	union0: PROCESS_HEAP_ENTRY_union0,
}

#[repr(C)]
union PROCESS_HEAP_ENTRY_union0 {
	Block: PROCESS_HEAP_ENTRY_Block,
	Region: PROCESS_HEAP_ENTRY_Region,
}

/// [`PROCESS_HEAP_ENTRY`](crate::PROCESS_HEAP_ENTRY) `Block`.
#[repr(C)]
#[derive(Clone, Copy)]
pub struct PROCESS_HEAP_ENTRY_Block {
	pub hMem: *mut std::ffi::c_void,
	dwReserved: [u32; 3],
}

/// [`PROCESS_HEAP_ENTRY`](crate::PROCESS_HEAP_ENTRY) `Region`.
#[repr(C)]
#[derive(Clone, Copy)]
pub struct PROCESS_HEAP_ENTRY_Region {
	pub dwCommittedSize: u32,
	pub dwUnCommittedSize: u32,
	pub lpFirstBlock: *mut std::ffi::c_void,
	pub lpLastBlock: *mut std::ffi::c_void,
}

impl_default!(PROCESS_HEAP_ENTRY);

impl PROCESS_HEAP_ENTRY {
	/// Retrieves the `Block` union field.
	#[must_use]
	pub const fn Block(&self) -> Option<&PROCESS_HEAP_ENTRY_Block> {
		if self.wFlags.has(co::PROCESS_HEAP::ENTRY_MOVEABLE) {
			Some(unsafe { &self.union0.Block })
		} else {
			None
		}
	}

	/// Retrieves the `Region` union field.
	#[must_use]
	pub const fn Region(&self) -> Option<&PROCESS_HEAP_ENTRY_Region> {
		if self.wFlags.has(co::PROCESS_HEAP::REGION) {
			Some(unsafe { &self.union0.Region })
		} else {
			None
		}
	}
}

/// [`PROCESS_INFORMATION`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-process_information)
/// struct.
#[repr(C)]
pub struct PROCESS_INFORMATION {
	pub hProcess: HPROCESS,
	pub hThread: HTHREAD,
	pub dwProcessId: u32,
	pub dwThreadId: u32,
}

impl_default!(PROCESS_INFORMATION);

/// [`PROCESSENTRY32`](https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/ns-tlhelp32-processentry32w)
/// struct.
#[repr(C)]
pub struct PROCESSENTRY32 {
	dwSize: u32,
	cntUsage: u32,
	pub th32ProcessID: u32,
	th32DefaultHeapID: usize,
	th32ModuleID: u32,
	pub cntThreads: u32,
	pub th32ParentProcessID: u32,
	pub pcPriClassBase: i32,
	dwFlags: u32,
	szExeFile: [u16; MAX_PATH],
}

impl_default!(PROCESSENTRY32, dwSize);

impl PROCESSENTRY32 {
	pub_fn_string_arr_get_set!(szExeFile, set_szExeFile);
}

/// [`PROCESSOR_NUMBER`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-processor_number)
/// struct.
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub struct PROCESSOR_NUMBER {
	pub Group: u16,
	pub Number: u8,
	Reserved: u8,
}

/// [`SECURITY_ATTRIBUTES`](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa379560(v=vs.85))
/// struct.
#[repr(C)]
pub struct SECURITY_ATTRIBUTES<'a> {
	nLength: u32,
	lpSecurityDescriptor: *mut SECURITY_DESCRIPTOR,
	bInheritHandle: i32,

	_lpSecurityDescriptor: PhantomData<&'a mut SECURITY_DESCRIPTOR>,
}

impl_default!(SECURITY_ATTRIBUTES, nLength, 'a);

impl<'a> SECURITY_ATTRIBUTES<'a> {
	pub_fn_ptr_get_set!('a, lpSecurityDescriptor, set_lpSecurityDescriptor, SECURITY_DESCRIPTOR);
	pub_fn_bool_get_set!(bInheritHandle, set_bInheritHandle);
}

/// [`SECURITY_DESCRIPTOR`](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-security_descriptor)
/// struct.
///
/// This struct can be initialized with
/// [`InitializeSecurityDescriptor`](crate::InitializeSecurityDescriptor)
/// function.
#[repr(C)]
pub struct SECURITY_DESCRIPTOR {
	pub Revision: u8,
	pub Sbz1: u8,
	pub Control: co::SE,
	pub Owner: *mut std::ffi::c_void,
	pub Group: *mut std::ffi::c_void,
	pub Sacl: *mut ACL,
	pub Dacl: *mut ACL,
}

/// [`STARTUPINFO`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow)
/// struct.
#[repr(C)]
pub struct STARTUPINFO<'a, 'b> {
	cb: u32,
	lpReserved: *mut u16,
	lpDesktop: *mut u16,
	lpTitle: *mut u16,
	pub dwX: u32,
	pub dwY: u32,
	pub dwXSize: u32,
	pub dwYSize: u32,
	pub dwXCountChars: u32,
	pub dwYCountChars: u32,
	pub dwFillAttribute: u32,
	pub dwFlags: co::STARTF,
	wShowWindow: u16, // co::SW, should be 32-bit
	cbReserved2: u16,
	lpReserved2: *mut u8,
	pub hStdInput: HPIPE,
	pub hStdOutput: HPIPE,
	pub hStdError: HPIPE,

	_lpDesktop: PhantomData<&'a mut u16>,
	_lpTitle: PhantomData<&'b mut u16>,
}

impl_default!(STARTUPINFO, cb, 'a, 'b);

impl<'a, 'b> STARTUPINFO<'a, 'b> {
	pub_fn_string_ptr_get_set!('a, lpDesktop, set_lpDesktop);
	pub_fn_string_ptr_get_set!('a, lpTitle, set_lpTitle);

	/// Returns the `wShowWindow` field.
	#[must_use]
	pub const fn wShowWindow(&self) -> co::SW {
		unsafe { co::SW::from_raw(self.wShowWindow as _) }
	}

	/// Sets the `wShowWindow` field.
	pub const fn set_wShowWindow(&mut self, val: co::SW) {
		self.wShowWindow = val.raw() as _;
	}
}

/// [`SYSTEM_INFO`](https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info)
/// struct.
#[repr(C)]
pub struct SYSTEM_INFO {
	pub wProcessorArchitecture: co::PROCESSOR_ARCHITECTURE,
	wReserved: u16,
	pub dwPageSize: u32,
	pub lpMinimumApplicationAddress: *mut std::ffi::c_void,
	pub lpMaximumApplicationAddress: *mut std::ffi::c_void,
	pub dwActiveProcessorMask: usize,
	pub dwNumberOfProcessors: u32,
	pub dwProcessorType: co::PROCESSOR,
	pub dwAllocationGranularity: u32,
	pub wProcessorLevel: u16,
	pub wProcessorRevision: u16,
}

impl_default!(SYSTEM_INFO);

/// [`SYSTEMTIME`](https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime)
/// struct.
///
/// Can be converted to [`FILETIME`](crate::FILETIME) with
/// [`SystemTimeToFileTime`](crate::SystemTimeToFileTime) function.
#[repr(C)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub struct SYSTEMTIME {
	/// The year. The valid values for this member are 1,601 through 30,827.
	pub wYear: u16,
	/// The month. January = 1.
	pub wMonth: u16,
	/// The day of the week. Sunday = 0.
	pub wDayOfWeek: u16,
	/// The day of the month. The valid values for this member are 1 through 31.
	pub wDay: u16,
	/// The hour. The valid values for this member are 0 through 23.
	pub wHour: u16,
	/// The minute. The valid values for this member are 0 through 59.
	pub wMinute: u16,
	/// The second. The valid values for this member are 0 through 59.
	pub wSecond: u16,
	/// The millisecond. The valid values for this member are 0 through 999.
	pub wMilliseconds: u16,
}

impl std::fmt::Display for SYSTEMTIME {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		write!(
			f,
			"{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}",
			self.wYear,
			self.wMonth,
			self.wDay,
			self.wHour,
			self.wMinute,
			self.wSecond,
			self.wMilliseconds
		)
	}
}

impl SYSTEMTIME {
	/// Returns a new `SYSTEMTIME` with the milliseconds difference.
	///
	/// Performs intermediate [`FILETIME`](crate::FILETIME) conversions.
	#[must_use]
	pub fn add_ms(self, ms: i64) -> SysResult<Self> {
		let ft = SystemTimeToFileTime(&self)?;
		FileTimeToSystemTime(&ft.add_ms(ms))
	}

	/// Returns a new `SYSTEMTIME` with the seconds difference.
	///
	/// Performs intermediate [`FILETIME`](crate::FILETIME) conversions.
	#[must_use]
	pub fn add_secs(self, secs: i64) -> SysResult<Self> {
		self.add_ms(secs * 1000)
	}

	/// Returns a new `SYSTEMTIME` with the minutes difference.
	///
	/// Performs intermediate [`FILETIME`](crate::FILETIME) conversions.
	#[must_use]
	pub fn add_mins(self, mins: i64) -> SysResult<Self> {
		self.add_secs(mins * 60)
	}

	/// Returns a new `SYSTEMTIME` with the hours difference.
	///
	/// Performs intermediate [`FILETIME`](crate::FILETIME) conversions.
	#[must_use]
	pub fn add_hours(self, hours: i64) -> SysResult<Self> {
		self.add_mins(hours * 60)
	}

	/// Returns a new `SYSTEMTIME` with the days difference.
	///
	/// Performs intermediate [`FILETIME`](crate::FILETIME) conversions.
	#[must_use]
	pub fn add_days(self, days: i64) -> SysResult<Self> {
		self.add_hours(days * 24)
	}
}

/// [`THREADENTRY32`](https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/ns-tlhelp32-threadentry32)
/// struct.
#[repr(C)]
pub struct THREADENTRY32 {
	dwSize: u32,
	cntUsage: u32,
	pub th32ThreadID: u32,
	pub th32OwnerProcessID: u32,
	pub tpBasePri: i32,
	tpDeltaPri: i32,
	dwFlags: u32,
}

impl_default!(THREADENTRY32, dwSize);

/// [`TIME_ZONE_INFORMATION`](https://learn.microsoft.com/en-us/windows/win32/api/timezoneapi/ns-timezoneapi-time_zone_information)
/// struct.
#[repr(C)]
#[derive(Default)]
pub struct TIME_ZONE_INFORMATION {
	pub bias: i32,
	standardName: [u16; 32],
	pub standardDate: SYSTEMTIME,
	pub standardBias: i32,
	daylightName: [u16; 32],
	pub daylightDate: SYSTEMTIME,
	pub daylightBias: i32,
}

impl TIME_ZONE_INFORMATION {
	pub_fn_string_arr_get_set!(standardName, set_standardName);
	pub_fn_string_arr_get_set!(daylightName, set_daylightName);
}

/// [`WIN32_FILE_ATTRIBUTE_DATA`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-win32_file_attribute_data)
/// struct.
#[repr(C)]
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub struct WIN32_FILE_ATTRIBUTE_DATA {
	pub dwFileAttributes: co::FILE_ATTRIBUTE,
	pub ftCreationTime: FILETIME,
	pub ftLastAccessTime: FILETIME,
	pub ftLastWriteTime: FILETIME,
	nFileSizeHigh: u32,
	nFileSizeLow: u32,
}

impl WIN32_FILE_ATTRIBUTE_DATA {
	/// Returns the nFileSizeHigh and nFileSizeLow fields.
	#[must_use]
	pub const fn nFileSize(&self) -> u64 {
		MAKEQWORD(self.nFileSizeLow, self.nFileSizeHigh)
	}

	/// Sets the nFileSizeHigh and nFileSizeLow fields.
	pub const fn set_nFileSize(&mut self, val: u64) {
		self.nFileSizeHigh = HIDWORD(val);
		self.nFileSizeLow = LODWORD(val);
	}
}

/// [`WIN32_FIND_DATA`](https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-win32_find_dataw)
/// struct.
#[repr(C)]
pub struct WIN32_FIND_DATA {
	pub dwFileAttributes: co::FILE_ATTRIBUTE,
	pub ftCreationTime: FILETIME,
	pub ftLastAccessTime: FILETIME,
	pub tLastWriteTime: FILETIME,
	nFileSizeHigh: u32,
	nFileSizeLow: u32,
	dwReserved0: u32,
	dwReserved1: u32,
	cFileName: [u16; MAX_PATH],
	cAlternateFileName: [u16; 14],
}

impl_default!(WIN32_FIND_DATA);

impl WIN32_FIND_DATA {
	/// Returns the nFileSizeHigh and nFileSizeLow fields.
	#[must_use]
	pub const fn nFileSize(&self) -> u64 {
		MAKEQWORD(self.nFileSizeLow, self.nFileSizeHigh)
	}

	/// Sets the nFileSizeHigh and nFileSizeLow fields.
	pub const fn set_nFileSize(&mut self, val: u64) {
		self.nFileSizeHigh = HIDWORD(val);
		self.nFileSizeLow = LODWORD(val);
	}

	pub_fn_string_arr_get_set!(cFileName, set_cFileName);
	pub_fn_string_arr_get_set!(cAlternateFileName, set_cAlternateFileName);
}