1 /**
2     Translation Windows of Core Audio interfaces: MMDevice, WASAPI, EndpointVolume API header files.
3 
4     Windows only.
5 
6 ```
7     // Useful helper functions: setHighThreadPriority && restoreThreadPriority.
8 
9     // use setHighThreadPriority to boost current thread priority
10     void * hTask = setHighThreadPriority();
11 
12     // play audio
13 
14     // restore normal priority
15     restoreThreadPriority(hTask);
16 ```
17 
18 */
19 module wasapi.coreaudio;
20 version(Windows):
21 
22 import core.sys.windows.windows;
23 import core.sys.windows.objidl;
24 import core.sys.windows.wtypes;
25 //import std.string;
26 
27 /// Helper function to create GUID from string.
28 ///
29 /// BCDE0395-E52F-467C-8E3D-C4579291692E -> GUID(0xBCDE0395, 0xE52F, 0x467C, [0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E])
30 GUID makeGuid(string str)()
31 {
32     static assert(str.length==36, "Guid string must be 36 chars long");
33     enum GUIDstring = "GUID(0x" ~ str[0..8] ~ ", 0x" ~ str[9..13] ~ ", 0x" ~ str[14..18] ~
34         ", [0x" ~ str[19..21] ~ ", 0x" ~ str[21..23] ~ ", 0x" ~ str[24..26] ~ ", 0x" ~ str[26..28]
35         ~ ", 0x" ~ str[28..30] ~ ", 0x" ~ str[30..32] ~ ", 0x" ~ str[32..34] ~ ", 0x" ~ str[34..36] ~ "])";
36     return mixin(GUIDstring);
37 }
38 
39 /** WASAPI Constants */
40 
41 uint AUDCLNT_ERR(uint n)() { return n | 0x88890000; }
42 
43 enum AUDCLNT_E_NOT_INITIALIZED              =AUDCLNT_ERR!(0x001);
44 enum AUDCLNT_E_ALREADY_INITIALIZED          =AUDCLNT_ERR!(0x002);
45 enum AUDCLNT_E_WRONG_ENDPOINT_TYPE          =AUDCLNT_ERR!(0x003);
46 enum AUDCLNT_E_DEVICE_INVALIDATED           =AUDCLNT_ERR!(0x004);
47 enum AUDCLNT_E_NOT_STOPPED                  =AUDCLNT_ERR!(0x005);
48 enum AUDCLNT_E_BUFFER_TOO_LARGE             =AUDCLNT_ERR!(0x006);
49 enum AUDCLNT_E_OUT_OF_ORDER                 =AUDCLNT_ERR!(0x007);
50 enum AUDCLNT_E_UNSUPPORTED_FORMAT           =AUDCLNT_ERR!(0x008);
51 enum AUDCLNT_E_INVALID_SIZE                 =AUDCLNT_ERR!(0x009);
52 enum AUDCLNT_E_DEVICE_IN_USE                =AUDCLNT_ERR!(0x00a);
53 enum AUDCLNT_E_BUFFER_OPERATION_PENDING     =AUDCLNT_ERR!(0x00b);
54 enum AUDCLNT_E_THREAD_NOT_REGISTERED        =AUDCLNT_ERR!(0x00c);
55 enum AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED   =AUDCLNT_ERR!(0x00e);
56 enum AUDCLNT_E_ENDPOINT_CREATE_FAILED       =AUDCLNT_ERR!(0x00f);
57 enum AUDCLNT_E_SERVICE_NOT_RUNNING          =AUDCLNT_ERR!(0x010);
58 enum AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED     =AUDCLNT_ERR!(0x011);
59 enum AUDCLNT_E_EXCLUSIVE_MODE_ONLY          =AUDCLNT_ERR!(0x012);
60 enum AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL =AUDCLNT_ERR!(0x013);
61 enum AUDCLNT_E_EVENTHANDLE_NOT_SET          =AUDCLNT_ERR!(0x014);
62 enum AUDCLNT_E_INCORRECT_BUFFER_SIZE        =AUDCLNT_ERR!(0x015);
63 enum AUDCLNT_E_BUFFER_SIZE_ERROR            =AUDCLNT_ERR!(0x016);
64 enum AUDCLNT_E_CPUUSAGE_EXCEEDED            =AUDCLNT_ERR!(0x017);
65 enum AUDCLNT_E_BUFFER_ERROR                 =AUDCLNT_ERR!(0x018);
66 enum AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED      =AUDCLNT_ERR!(0x019);
67 enum AUDCLNT_E_INVALID_DEVICE_PERIOD        =AUDCLNT_ERR!(0x020);
68 enum AUDCLNT_E_INVALID_STREAM_FLAG          =AUDCLNT_ERR!(0x021);
69 enum AUDCLNT_E_ENDPOINT_OFFLOAD_NOT_CAPABLE =AUDCLNT_ERR!(0x022);
70 enum AUDCLNT_E_OUT_OF_OFFLOAD_RESOURCES     =AUDCLNT_ERR!(0x023);
71 enum AUDCLNT_E_OFFLOAD_MODE_ONLY            =AUDCLNT_ERR!(0x024);
72 enum AUDCLNT_E_NONOFFLOAD_MODE_ONLY         =AUDCLNT_ERR!(0x025);
73 enum AUDCLNT_E_RESOURCES_INVALIDATED        =AUDCLNT_ERR!(0x026);
74 enum AUDCLNT_E_RAW_MODE_UNSUPPORTED         =AUDCLNT_ERR!(0x027);
75 enum AUDCLNT_E_ENGINE_PERIODICITY_LOCKED    =AUDCLNT_ERR!(0x028);
76 enum AUDCLNT_E_ENGINE_FORMAT_LOCKED         =AUDCLNT_ERR!(0x029);
77 
78 
79 extern (Windows):
80 
81 enum WAVE_FORMAT_UNKNOWN                    =0x0000; /* Microsoft Corporation */
82 enum WAVE_FORMAT_ADPCM                      =0x0002; /* Microsoft Corporation */
83 enum WAVE_FORMAT_IEEE_FLOAT                 =0x0003; /* Microsoft Corporation */
84 enum WAVE_FORMAT_VSELP                      =0x0004; /* Compaq Computer Corp. */
85 enum WAVE_FORMAT_IBM_CVSD                   =0x0005; /* IBM Corporation */
86 enum WAVE_FORMAT_ALAW                       =0x0006; /* Microsoft Corporation */
87 enum WAVE_FORMAT_MULAW                      =0x0007; /* Microsoft Corporation */
88 enum WAVE_FORMAT_DTS                        =0x0008; /* Microsoft Corporation */
89 enum WAVE_FORMAT_DRM                        =0x0009; /* Microsoft Corporation */
90 enum WAVE_FORMAT_WMAVOICE9                  =0x000A; /* Microsoft Corporation */
91 enum WAVE_FORMAT_WMAVOICE10                 =0x000B; /* Microsoft Corporation */
92 enum WAVE_FORMAT_OKI_ADPCM                  =0x0010; /* OKI */
93 enum WAVE_FORMAT_DVI_ADPCM                  =0x0011; /* Intel Corporation */
94 enum WAVE_FORMAT_IMA_ADPCM                  =(WAVE_FORMAT_DVI_ADPCM); /*  Intel Corporation */
95 enum WAVE_FORMAT_MEDIASPACE_ADPCM           =0x0012; /* Videologic */
96 enum WAVE_FORMAT_SIERRA_ADPCM               =0x0013; /* Sierra Semiconductor Corp */
97 enum WAVE_FORMAT_G723_ADPCM                 =0x0014; /* Antex Electronics Corporation */
98 enum WAVE_FORMAT_DIGISTD                    =0x0015; /* DSP Solutions, Inc. */
99 enum WAVE_FORMAT_DIGIFIX                    =0x0016; /* DSP Solutions, Inc. */
100 enum WAVE_FORMAT_DIALOGIC_OKI_ADPCM         =0x0017; /* Dialogic Corporation */
101 enum WAVE_FORMAT_MEDIAVISION_ADPCM          =0x0018; /* Media Vision, Inc. */
102 enum WAVE_FORMAT_CU_CODEC                   =0x0019; /* Hewlett-Packard Company */
103 enum WAVE_FORMAT_YAMAHA_ADPCM               =0x0020; /* Yamaha Corporation of America */
104 enum WAVE_FORMAT_SONARC                     =0x0021; /* Speech Compression */
105 enum WAVE_FORMAT_DSPGROUP_TRUESPEECH        =0x0022; /* DSP Group, Inc */
106 enum WAVE_FORMAT_ECHOSC1                    =0x0023; /* Echo Speech Corporation */
107 enum WAVE_FORMAT_AUDIOFILE_AF36             =0x0024; /* Virtual Music, Inc. */
108 enum WAVE_FORMAT_APTX                       =0x0025; /* Audio Processing Technology */
109 enum WAVE_FORMAT_AUDIOFILE_AF10             =0x0026; /* Virtual Music, Inc. */
110 enum WAVE_FORMAT_PROSODY_1612               =0x0027; /* Aculab plc */
111 enum WAVE_FORMAT_LRC                        =0x0028; /* Merging Technologies S.A. */
112 enum WAVE_FORMAT_DOLBY_AC2                  =0x0030; /* Dolby Laboratories */
113 enum WAVE_FORMAT_GSM610                     =0x0031; /* Microsoft Corporation */
114 enum WAVE_FORMAT_MSNAUDIO                   =0x0032; /* Microsoft Corporation */
115 enum WAVE_FORMAT_ANTEX_ADPCME               =0x0033; /* Antex Electronics Corporation */
116 enum WAVE_FORMAT_CONTROL_RES_VQLPC          =0x0034; /* Control Resources Limited */
117 enum WAVE_FORMAT_DIGIREAL                   =0x0035; /* DSP Solutions, Inc. */
118 enum WAVE_FORMAT_DIGIADPCM                  =0x0036; /* DSP Solutions, Inc. */
119 enum WAVE_FORMAT_CONTROL_RES_CR10           =0x0037; /* Control Resources Limited */
120 enum WAVE_FORMAT_NMS_VBXADPCM               =0x0038; /* Natural MicroSystems */
121 enum WAVE_FORMAT_CS_IMAADPCM                =0x0039; /* Crystal Semiconductor IMA ADPCM */
122 enum WAVE_FORMAT_ECHOSC3                    =0x003A; /* Echo Speech Corporation */
123 enum WAVE_FORMAT_ROCKWELL_ADPCM             =0x003B; /* Rockwell International */
124 enum WAVE_FORMAT_ROCKWELL_DIGITALK          =0x003C; /* Rockwell International */
125 enum WAVE_FORMAT_XEBEC                      =0x003D; /* Xebec Multimedia Solutions Limited */
126 enum WAVE_FORMAT_G721_ADPCM                 =0x0040; /* Antex Electronics Corporation */
127 enum WAVE_FORMAT_G728_CELP                  =0x0041; /* Antex Electronics Corporation */
128 enum WAVE_FORMAT_MSG723                     =0x0042; /* Microsoft Corporation */
129 enum WAVE_FORMAT_MPEG                       =0x0050; /* Microsoft Corporation */
130 enum WAVE_FORMAT_RT24                       =0x0052; /* InSoft, Inc. */
131 enum WAVE_FORMAT_PAC                        =0x0053; /* InSoft, Inc. */
132 enum WAVE_FORMAT_MPEGLAYER3                 =0x0055; /* ISO/MPEG Layer3 Format Tag */
133 enum WAVE_FORMAT_LUCENT_G723                =0x0059; /* Lucent Technologies */
134 enum WAVE_FORMAT_CIRRUS                     =0x0060; /* Cirrus Logic */
135 enum WAVE_FORMAT_ESPCM                      =0x0061; /* ESS Technology */
136 enum WAVE_FORMAT_VOXWARE                    =0x0062; /* Voxware Inc */
137 enum WAVE_FORMAT_CANOPUS_ATRAC              =0x0063; /* Canopus, co., Ltd. */
138 enum WAVE_FORMAT_G726_ADPCM                 =0x0064; /* APICOM */
139 enum WAVE_FORMAT_G722_ADPCM                 =0x0065; /* APICOM */
140 enum WAVE_FORMAT_DSAT_DISPLAY               =0x0067; /* Microsoft Corporation */
141 enum WAVE_FORMAT_VOXWARE_BYTE_ALIGNED       =0x0069; /* Voxware Inc */
142 enum WAVE_FORMAT_VOXWARE_AC8                =0x0070; /* Voxware Inc */
143 enum WAVE_FORMAT_VOXWARE_AC10               =0x0071; /* Voxware Inc */
144 enum WAVE_FORMAT_VOXWARE_AC16               =0x0072; /* Voxware Inc */
145 enum WAVE_FORMAT_VOXWARE_AC20               =0x0073; /* Voxware Inc */
146 enum WAVE_FORMAT_VOXWARE_RT24               =0x0074; /* Voxware Inc */
147 enum WAVE_FORMAT_VOXWARE_RT29               =0x0075; /* Voxware Inc */
148 enum WAVE_FORMAT_VOXWARE_RT29HW             =0x0076; /* Voxware Inc */
149 enum WAVE_FORMAT_VOXWARE_VR12               =0x0077; /* Voxware Inc */
150 enum WAVE_FORMAT_VOXWARE_VR18               =0x0078; /* Voxware Inc */
151 enum WAVE_FORMAT_VOXWARE_TQ40               =0x0079; /* Voxware Inc */
152 enum WAVE_FORMAT_SOFTSOUND                  =0x0080; /* Softsound, Ltd. */
153 enum WAVE_FORMAT_VOXWARE_TQ60               =0x0081; /* Voxware Inc */
154 enum WAVE_FORMAT_MSRT24                     =0x0082; /* Microsoft Corporation */
155 enum WAVE_FORMAT_G729A                      =0x0083; /* AT&T Labs, Inc. */
156 enum WAVE_FORMAT_MVI_MVI2                   =0x0084; /* Motion Pixels */
157 enum WAVE_FORMAT_DF_G726                    =0x0085; /* DataFusion Systems (Pty) (Ltd) */
158 enum WAVE_FORMAT_DF_GSM610                  =0x0086; /* DataFusion Systems (Pty) (Ltd) */
159 enum WAVE_FORMAT_ISIAUDIO                   =0x0088; /* Iterated Systems, Inc. */
160 enum WAVE_FORMAT_ONLIVE                     =0x0089; /* OnLive! Technologies, Inc. */
161 enum WAVE_FORMAT_SBC24                      =0x0091; /* Siemens Business Communications Sys */
162 enum WAVE_FORMAT_DOLBY_AC3_SPDIF            =0x0092; /* Sonic Foundry */
163 enum WAVE_FORMAT_MEDIASONIC_G723            =0x0093; /* MediaSonic */
164 enum WAVE_FORMAT_PROSODY_8KBPS              =0x0094; /* Aculab plc */
165 enum WAVE_FORMAT_ZYXEL_ADPCM                =0x0097; /* ZyXEL Communications, Inc. */
166 enum WAVE_FORMAT_PHILIPS_LPCBB              =0x0098; /* Philips Speech Processing */
167 enum WAVE_FORMAT_PACKED                     =0x0099; /* Studer Professional Audio AG */
168 enum WAVE_FORMAT_MALDEN_PHONYTALK           =0x00A0; /* Malden Electronics Ltd. */
169 enum WAVE_FORMAT_RAW_AAC1                   =0x00FF; /* For Raw AAC, with format block AudioSpecificConfig() (as defined by MPEG-4), that follows WAVEFORMATEX */
170 enum WAVE_FORMAT_RHETOREX_ADPCM             =0x0100; /* Rhetorex Inc. */
171 enum WAVE_FORMAT_IRAT                       =0x0101; /* BeCubed Software Inc. */
172 enum WAVE_FORMAT_VIVO_G723                  =0x0111; /* Vivo Software */
173 enum WAVE_FORMAT_VIVO_SIREN                 =0x0112; /* Vivo Software */
174 enum WAVE_FORMAT_DIGITAL_G723               =0x0123; /* Digital Equipment Corporation */
175 enum WAVE_FORMAT_SANYO_LD_ADPCM             =0x0125; /* Sanyo Electric Co., Ltd. */
176 enum WAVE_FORMAT_SIPROLAB_ACEPLNET          =0x0130; /* Sipro Lab Telecom Inc. */
177 enum WAVE_FORMAT_SIPROLAB_ACELP4800         =0x0131; /* Sipro Lab Telecom Inc. */
178 enum WAVE_FORMAT_SIPROLAB_ACELP8V3          =0x0132; /* Sipro Lab Telecom Inc. */
179 enum WAVE_FORMAT_SIPROLAB_G729              =0x0133; /* Sipro Lab Telecom Inc. */
180 enum WAVE_FORMAT_SIPROLAB_G729A             =0x0134; /* Sipro Lab Telecom Inc. */
181 enum WAVE_FORMAT_SIPROLAB_KELVIN            =0x0135; /* Sipro Lab Telecom Inc. */
182 enum WAVE_FORMAT_G726ADPCM                  =0x0140; /* Dictaphone Corporation */
183 enum WAVE_FORMAT_QUALCOMM_PUREVOICE         =0x0150; /* Qualcomm, Inc. */
184 enum WAVE_FORMAT_QUALCOMM_HALFRATE          =0x0151; /* Qualcomm, Inc. */
185 enum WAVE_FORMAT_TUBGSM                     =0x0155; /* Ring Zero Systems, Inc. */
186 enum WAVE_FORMAT_MSAUDIO1                   =0x0160; /* Microsoft Corporation */
187 enum WAVE_FORMAT_WMAUDIO2                   =0x0161; /* Microsoft Corporation */
188 enum WAVE_FORMAT_WMAUDIO3                   =0x0162; /* Microsoft Corporation */
189 enum WAVE_FORMAT_WMAUDIO_LOSSLESS           =0x0163; /* Microsoft Corporation */
190 enum WAVE_FORMAT_WMASPDIF                   =0x0164; /* Microsoft Corporation */
191 enum WAVE_FORMAT_UNISYS_NAP_ADPCM           =0x0170; /* Unisys Corp. */
192 enum WAVE_FORMAT_UNISYS_NAP_ULAW            =0x0171; /* Unisys Corp. */
193 enum WAVE_FORMAT_UNISYS_NAP_ALAW            =0x0172; /* Unisys Corp. */
194 enum WAVE_FORMAT_UNISYS_NAP_16K             =0x0173; /* Unisys Corp. */
195 enum WAVE_FORMAT_CREATIVE_ADPCM             =0x0200; /* Creative Labs, Inc */
196 enum WAVE_FORMAT_CREATIVE_FASTSPEECH8       =0x0202; /* Creative Labs, Inc */
197 enum WAVE_FORMAT_CREATIVE_FASTSPEECH10      =0x0203; /* Creative Labs, Inc */
198 enum WAVE_FORMAT_UHER_ADPCM                 =0x0210; /* UHER informatic GmbH */
199 enum WAVE_FORMAT_QUARTERDECK                =0x0220; /* Quarterdeck Corporation */
200 enum WAVE_FORMAT_ILINK_VC                   =0x0230; /* I-link Worldwide */
201 enum WAVE_FORMAT_RAW_SPORT                  =0x0240; /* Aureal Semiconductor */
202 enum WAVE_FORMAT_ESST_AC3                   =0x0241; /* ESS Technology, Inc. */
203 enum WAVE_FORMAT_GENERIC_PASSTHRU           =0x0249;
204 enum WAVE_FORMAT_IPI_HSX                    =0x0250; /* Interactive Products, Inc. */
205 enum WAVE_FORMAT_IPI_RPELP                  =0x0251; /* Interactive Products, Inc. */
206 enum WAVE_FORMAT_CS2                        =0x0260; /* Consistent Software */
207 enum WAVE_FORMAT_SONY_SCX                   =0x0270; /* Sony Corp. */
208 enum WAVE_FORMAT_FM_TOWNS_SND               =0x0300; /* Fujitsu Corp. */
209 enum WAVE_FORMAT_BTV_DIGITAL                =0x0400; /* Brooktree Corporation */
210 enum WAVE_FORMAT_QDESIGN_MUSIC              =0x0450; /* QDesign Corporation */
211 enum WAVE_FORMAT_VME_VMPCM                  =0x0680; /* AT&T Labs, Inc. */
212 enum WAVE_FORMAT_TPC                        =0x0681; /* AT&T Labs, Inc. */
213 enum WAVE_FORMAT_OLIGSM                     =0x1000; /* Ing C. Olivetti & C., S.p.A. */
214 enum WAVE_FORMAT_OLIADPCM                   =0x1001; /* Ing C. Olivetti & C., S.p.A. */
215 enum WAVE_FORMAT_OLICELP                    =0x1002; /* Ing C. Olivetti & C., S.p.A. */
216 enum WAVE_FORMAT_OLISBC                     =0x1003; /* Ing C. Olivetti & C., S.p.A. */
217 enum WAVE_FORMAT_OLIOPR                     =0x1004; /* Ing C. Olivetti & C., S.p.A. */
218 enum WAVE_FORMAT_LH_CODEC                   =0x1100; /* Lernout & Hauspie */
219 enum WAVE_FORMAT_NORRIS                     =0x1400; /* Norris Communications, Inc. */
220 enum WAVE_FORMAT_SOUNDSPACE_MUSICOMPRESS    =0x1500; /* AT&T Labs, Inc. */
221 enum WAVE_FORMAT_MPEG_ADTS_AAC              =0x1600; /* Microsoft Corporation */
222 enum WAVE_FORMAT_MPEG_RAW_AAC               =0x1601; /* Microsoft Corporation */
223 enum WAVE_FORMAT_MPEG_LOAS                  =0x1602; /* Microsoft Corporation (MPEG-4 Audio Transport Streams (LOAS/LATM) */
224 enum WAVE_FORMAT_NOKIA_MPEG_ADTS_AAC        =0x1608; /* Microsoft Corporation */
225 enum WAVE_FORMAT_NOKIA_MPEG_RAW_AAC         =0x1609; /* Microsoft Corporation */
226 enum WAVE_FORMAT_VODAFONE_MPEG_ADTS_AAC     =0x160A; /* Microsoft Corporation */
227 enum WAVE_FORMAT_VODAFONE_MPEG_RAW_AAC      =0x160B; /* Microsoft Corporation */
228 enum WAVE_FORMAT_MPEG_HEAAC                 =0x1610; /* Microsoft Corporation (MPEG-2 AAC or MPEG-4 HE-AAC v1/v2 streams with any payload (ADTS, ADIF, LOAS/LATM, RAW). Format block includes MP4 AudioSpecificConfig() -- see HEAACWAVEFORMAT below */
229 enum WAVE_FORMAT_DVM                        =0x2000; /* FAST Multimedia AG */
230 enum WAVE_FORMAT_DTS2                       =0x2001;
231 enum WAVE_FORMAT_EXTENSIBLE                 =0xFFFE; /* Microsoft */
232 
233 enum {
234     SPEAKER_FRONT_LEFT = 1,
235     SPEAKER_FRONT_RIGHT = 2,
236 }
237 
238 const GUID MEDIASUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, [0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]};
239 const GUID MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, [0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]};
240 
241 struct WAVEFORMATEXTENSIBLE {
242     WAVEFORMATEX    Format;
243     alias Format this;
244     union {
245         WORD wValidBitsPerSample;       /* bits of precision  */
246         WORD wSamplesPerBlock;          /* valid if wBitsPerSample==0 */
247         WORD wReserved;                 /* If neither applies, set to zero. */
248     }
249     DWORD           dwChannelMask;      /* which channels are */
250     /* present in stream  */
251     GUID            SubFormat;
252 }
253 
254 struct PROPERTYKEY
255 {
256     GUID fmtid;
257     DWORD pid;
258 }
259 
260 alias DEVPROPGUID = GUID;
261 alias DEVPROPID = ULONG;
262 
263 alias DEVPROPKEY = PROPERTYKEY;
264 
265 //#define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) EXTERN_C const DEVPROPKEY DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
266 
267 DEVPROPKEY DEFINE_DEVPROPKEY(DWORD l, WORD w1, WORD w2, BYTE b1, BYTE b2, BYTE b3, BYTE b4, BYTE b5, BYTE b6, BYTE b7, BYTE b8, ULONG pid)() {
268     DEVPROPKEY a =
269         { { l, w1, w2, [ b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 ] }, pid };
270     return a;
271 }
272 
273 //
274 // DEVPKEY_NAME
275 // Common DEVPKEY used to retrieve the display name for an object.
276 //
277 const DEVPKEY_NAME = DEFINE_DEVPROPKEY!(0xb725f130, 0x47ef, 0x101a, 0xa5, 0xf1, 0x02, 0x60, 0x8c, 0x9e, 0xeb, 0xac, 10);    // DEVPROP_TYPE_STRING
278 
279 
280 //
281 // Device properties
282 // These DEVPKEYs correspond to the SetupAPI SPDRP_XXX device properties.
283 //
284 const DEVPKEY_Device_DeviceDesc = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 2);     // DEVPROP_TYPE_STRING
285 const DEVPKEY_Device_HardwareIds = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 3);     // DEVPROP_TYPE_STRING_LIST
286 const DEVPKEY_Device_CompatibleIds = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 4);     // DEVPROP_TYPE_STRING_LIST
287 const DEVPKEY_Device_Service = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 6);     // DEVPROP_TYPE_STRING
288 const DEVPKEY_Device_Class = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 9);     // DEVPROP_TYPE_STRING
289 const DEVPKEY_Device_ClassGuid = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 10);    // DEVPROP_TYPE_GUID
290 const DEVPKEY_Device_Driver = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 11);    // DEVPROP_TYPE_STRING
291 const DEVPKEY_Device_ConfigFlags = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 12);    // DEVPROP_TYPE_UINT32
292 const DEVPKEY_Device_Manufacturer = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 13);    // DEVPROP_TYPE_STRING
293 const DEVPKEY_Device_FriendlyName = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14);    // DEVPROP_TYPE_STRING
294 const DEVPKEY_Device_LocationInfo = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 15);    // DEVPROP_TYPE_STRING
295 const DEVPKEY_Device_PDOName = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 16);    // DEVPROP_TYPE_STRING
296 const DEVPKEY_Device_Capabilities = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 17);    // DEVPROP_TYPE_UNINT32
297 const DEVPKEY_Device_UINumber = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 18);    // DEVPROP_TYPE_STRING
298 const DEVPKEY_Device_UpperFilters = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 19);    // DEVPROP_TYPE_STRING_LIST
299 const DEVPKEY_Device_LowerFilters = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 20);    // DEVPROP_TYPE_STRING_LIST
300 const DEVPKEY_Device_BusTypeGuid = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 21);    // DEVPROP_TYPE_GUID
301 const DEVPKEY_Device_LegacyBusType = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 22);    // DEVPROP_TYPE_UINT32
302 const DEVPKEY_Device_BusNumber = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 23);    // DEVPROP_TYPE_UINT32
303 const DEVPKEY_Device_EnumeratorName = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 24);    // DEVPROP_TYPE_STRING
304 const DEVPKEY_Device_Security = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 25);    // DEVPROP_TYPE_SECURITY_DESCRIPTOR
305 const DEVPKEY_Device_SecuritySDS = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 26);    // DEVPROP_TYPE_SECURITY_DESCRIPTOR_STRING
306 const DEVPKEY_Device_DevType = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 27);    // DEVPROP_TYPE_UINT32
307 const DEVPKEY_Device_Exclusive = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 28);    // DEVPROP_TYPE_BOOLEAN
308 const DEVPKEY_Device_Characteristics = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 29);    // DEVPROP_TYPE_UINT32
309 const DEVPKEY_Device_Address = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 30);    // DEVPROP_TYPE_UINT32
310 const DEVPKEY_Device_UINumberDescFormat = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 31);    // DEVPROP_TYPE_STRING
311 const DEVPKEY_Device_PowerData = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 32);    // DEVPROP_TYPE_BINARY
312 const DEVPKEY_Device_RemovalPolicy = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 33);    // DEVPROP_TYPE_UINT32
313 const DEVPKEY_Device_RemovalPolicyDefault = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 34);    // DEVPROP_TYPE_UINT32
314 const DEVPKEY_Device_RemovalPolicyOverride = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 35);    // DEVPROP_TYPE_UINT32
315 const DEVPKEY_Device_InstallState = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 36);    // DEVPROP_TYPE_UINT32
316 const DEVPKEY_Device_LocationPaths = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 37);    // DEVPROP_TYPE_STRING_LIST
317 const DEVPKEY_Device_BaseContainerId = DEFINE_DEVPROPKEY!(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 38);    // DEVPROP_TYPE_GUID!
318 
319 //
320 // Device properties
321 // These DEVPKEYs correspond to a device's status and problem code.
322 //
323 const DEVPKEY_Device_DevNodeStatus = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 2);     // DEVPROP_TYPE_UINT32
324 const DEVPKEY_Device_ProblemCode = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 3);     // DEVPROP_TYPE_UINT32
325 
326 //
327 // Device properties
328 // These DEVPKEYs correspond to a device's relations.
329 //
330 const DEVPKEY_Device_EjectionRelations = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 4);     // DEVPROP_TYPE_STRING_LIST
331 const DEVPKEY_Device_RemovalRelations = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 5);     // DEVPROP_TYPE_STRING_LIST
332 const DEVPKEY_Device_PowerRelations = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 6);     // DEVPROP_TYPE_STRING_LIST
333 const DEVPKEY_Device_BusRelations = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 7);     // DEVPROP_TYPE_STRING_LIST
334 const DEVPKEY_Device_Parent = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 8);     // DEVPROP_TYPE_STRING
335 const DEVPKEY_Device_Children = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 9);     // DEVPROP_TYPE_STRING_LIST
336 const DEVPKEY_Device_Siblings = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 10);    // DEVPROP_TYPE_STRING_LIST
337 const DEVPKEY_Device_TransportRelations = DEFINE_DEVPROPKEY!(0x4340a6c5, 0x93fa, 0x4706, 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7, 11);    // DEVPROP_TYPE_STRING_LIST
338 
339 //
340 // Other Device properties
341 // These DEVPKEYs are set for the corresponding types of root-enumerated devices.     ;comment
342 //
343 const DEVPKEY_Device_Reported = DEFINE_DEVPROPKEY!(0x80497100, 0x8c73, 0x48b9, 0xaa, 0xd9, 0xce, 0x38, 0x7e, 0x19, 0xc5, 0x6e, 2);     // DEVPROP_TYPE_BOOLEAN
344 const DEVPKEY_Device_Legacy = DEFINE_DEVPROPKEY!(0x80497100, 0x8c73, 0x48b9, 0xaa, 0xd9, 0xce, 0x38, 0x7e, 0x19, 0xc5, 0x6e, 3);     // DEVPROP_TYPE_BOOLEAN
345 
346 //
347 // Device Instance Id
348 //
349 const DEVPKEY_Device_InstanceId = DEFINE_DEVPROPKEY!(0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57, 256);   // DEVPROP_TYPE_STRING
350 
351 //
352 // Device Container Id
353 //
354 const DEVPKEY_Device_ContainerId = DEFINE_DEVPROPKEY!(0x8c7ed206, 0x3f8a, 0x4827, 0xb3, 0xab, 0xae, 0x9e, 0x1f, 0xae, 0xfc, 0x6c, 2);     // DEVPROP_TYPE_GUID
355 
356 //
357 // Device Experience related Keys
358 //
359 const DEVPKEY_Device_ModelId = DEFINE_DEVPROPKEY!(0x80d81ea6, 0x7473, 0x4b0c, 0x82, 0x16, 0xef, 0xc1, 0x1a, 0x2c, 0x4c, 0x8b, 2);     // DEVPROP_TYPE_GUID
360 const DEVPKEY_Device_FriendlyNameAttributes = DEFINE_DEVPROPKEY!(0x80d81ea6, 0x7473, 0x4b0c, 0x82, 0x16, 0xef, 0xc1, 0x1a, 0x2c, 0x4c, 0x8b, 3);     // DEVPROP_TYPE_UINT32
361 const DEVPKEY_Device_ManufacturerAttributes = DEFINE_DEVPROPKEY!(0x80d81ea6, 0x7473, 0x4b0c, 0x82, 0x16, 0xef, 0xc1, 0x1a, 0x2c, 0x4c, 0x8b, 4);     // DEVPROP_TYPE_UINT32
362 const DEVPKEY_Device_PresenceNotForDevice = DEFINE_DEVPROPKEY!(0x80d81ea6, 0x7473, 0x4b0c, 0x82, 0x16, 0xef, 0xc1, 0x1a, 0x2c, 0x4c, 0x8b, 5);     // DEVPROP_TYPE_BOOLEAN
363 
364 //
365 // Other Device properties
366 //
367 const DEVPKEY_Numa_Proximity_Domain = DEFINE_DEVPROPKEY!(0x540b947e, 0x8b40, 0x45bc, 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2, 1);     // DEVPROP_TYPE_UINT32
368 const DEVPKEY_Device_DHP_Rebalance_Policy = DEFINE_DEVPROPKEY!(0x540b947e, 0x8b40, 0x45bc, 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2, 2);     // DEVPROP_TYPE_UINT32
369 const DEVPKEY_Device_Numa_Node = DEFINE_DEVPROPKEY!(0x540b947e, 0x8b40, 0x45bc, 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2, 3);     // DEVPROP_TYPE_UINT32
370 const DEVPKEY_Device_BusReportedDeviceDesc = DEFINE_DEVPROPKEY!(0x540b947e, 0x8b40, 0x45bc, 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2, 4);     // DEVPROP_TYPE_STRING
371 
372 
373 //
374 // Device Session Id
375 //
376 const DEVPKEY_Device_SessionId = DEFINE_DEVPROPKEY!(0x83da6326, 0x97a6, 0x4088, 0x94, 0x53, 0xa1, 0x92, 0x3f, 0x57, 0x3b, 0x29, 6);     // DEVPROP_TYPE_UINT32
377 
378 //
379 // Device activity timestamp properties
380 //
381 const DEVPKEY_Device_InstallDate = DEFINE_DEVPROPKEY!(0x83da6326, 0x97a6, 0x4088, 0x94, 0x53, 0xa1, 0x92, 0x3f, 0x57, 0x3b, 0x29, 100);   // DEVPROP_TYPE_FILETIME
382 const DEVPKEY_Device_FirstInstallDate = DEFINE_DEVPROPKEY!(0x83da6326, 0x97a6, 0x4088, 0x94, 0x53, 0xa1, 0x92, 0x3f, 0x57, 0x3b, 0x29, 101);   // DEVPROP_TYPE_FILETIME
383 
384 //
385 // Device driver properties
386 //
387 const DEVPKEY_Device_DriverDate = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 2);      // DEVPROP_TYPE_FILETIME
388 const DEVPKEY_Device_DriverVersion = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 3);      // DEVPROP_TYPE_STRING
389 const DEVPKEY_Device_DriverDesc = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 4);      // DEVPROP_TYPE_STRING
390 const DEVPKEY_Device_DriverInfPath = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 5);      // DEVPROP_TYPE_STRING
391 const DEVPKEY_Device_DriverInfSection = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 6);      // DEVPROP_TYPE_STRING
392 const DEVPKEY_Device_DriverInfSectionExt = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 7);      // DEVPROP_TYPE_STRING
393 const DEVPKEY_Device_MatchingDeviceId = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 8);      // DEVPROP_TYPE_STRING
394 const DEVPKEY_Device_DriverProvider = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 9);      // DEVPROP_TYPE_STRING
395 const DEVPKEY_Device_DriverPropPageProvider = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 10);     // DEVPROP_TYPE_STRING
396 const DEVPKEY_Device_DriverCoInstallers = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 11);     // DEVPROP_TYPE_STRING_LIST
397 const DEVPKEY_Device_ResourcePickerTags = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 12);     // DEVPROP_TYPE_STRING
398 const DEVPKEY_Device_ResourcePickerExceptions = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 13);   // DEVPROP_TYPE_STRING
399 const DEVPKEY_Device_DriverRank = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 14);     // DEVPROP_TYPE_UINT32
400 const DEVPKEY_Device_DriverLogoLevel = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 15);     // DEVPROP_TYPE_UINT32
401 
402 //
403 // Device properties
404 // These DEVPKEYs may be set by the driver package installed for a device.
405 //
406 const DEVPKEY_Device_NoConnectSound = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 17);     // DEVPROP_TYPE_BOOLEAN
407 const DEVPKEY_Device_GenericDriverInstalled = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 18);     // DEVPROP_TYPE_BOOLEAN
408 const DEVPKEY_Device_AdditionalSoftwareRequested = DEFINE_DEVPROPKEY!(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 19); //DEVPROP_TYPE_BOOLEAN
409 
410 //
411 // Device safe-removal properties
412 //
413 const DEVPKEY_Device_SafeRemovalRequired = DEFINE_DEVPROPKEY!(0xafd97640,  0x86a3, 0x4210, 0xb6, 0x7c, 0x28, 0x9c, 0x41, 0xaa, 0xbe, 0x55, 2);    // DEVPROP_TYPE_BOOLEAN
414 const DEVPKEY_Device_SafeRemovalRequiredOverride = DEFINE_DEVPROPKEY!(0xafd97640,  0x86a3, 0x4210, 0xb6, 0x7c, 0x28, 0x9c, 0x41, 0xaa, 0xbe, 0x55, 3); // DEVPROP_TYPE_BOOLEAN
415 
416 //
417 // Device properties
418 // These DEVPKEYs may be set by the driver package installed for a device.
419 //
420 const DEVPKEY_DrvPkg_Model = DEFINE_DEVPROPKEY!(0xcf73bb51, 0x3abf, 0x44a2, 0x85, 0xe0, 0x9a, 0x3d, 0xc7, 0xa1, 0x21, 0x32, 2);     // DEVPROP_TYPE_STRING
421 const DEVPKEY_DrvPkg_VendorWebSite = DEFINE_DEVPROPKEY!(0xcf73bb51, 0x3abf, 0x44a2, 0x85, 0xe0, 0x9a, 0x3d, 0xc7, 0xa1, 0x21, 0x32, 3);     // DEVPROP_TYPE_STRING
422 const DEVPKEY_DrvPkg_DetailedDescription = DEFINE_DEVPROPKEY!(0xcf73bb51, 0x3abf, 0x44a2, 0x85, 0xe0, 0x9a, 0x3d, 0xc7, 0xa1, 0x21, 0x32, 4);     // DEVPROP_TYPE_STRING
423 const DEVPKEY_DrvPkg_DocumentationLink = DEFINE_DEVPROPKEY!(0xcf73bb51, 0x3abf, 0x44a2, 0x85, 0xe0, 0x9a, 0x3d, 0xc7, 0xa1, 0x21, 0x32, 5);     // DEVPROP_TYPE_STRING
424 const DEVPKEY_DrvPkg_Icon = DEFINE_DEVPROPKEY!(0xcf73bb51, 0x3abf, 0x44a2, 0x85, 0xe0, 0x9a, 0x3d, 0xc7, 0xa1, 0x21, 0x32, 6);     // DEVPROP_TYPE_STRING_LIST
425 const DEVPKEY_DrvPkg_BrandingIcon = DEFINE_DEVPROPKEY!(0xcf73bb51, 0x3abf, 0x44a2, 0x85, 0xe0, 0x9a, 0x3d, 0xc7, 0xa1, 0x21, 0x32, 7);     // DEVPROP_TYPE_STRING_LIST
426 
427 
428 //
429 // Device setup class properties
430 // These DEVPKEYs correspond to the SetupAPI SPCRP_XXX setup class properties.
431 //
432 const DEVPKEY_DeviceClass_UpperFilters = DEFINE_DEVPROPKEY!(0x4321918b, 0xf69e, 0x470d, 0xa5, 0xde, 0x4d, 0x88, 0xc7, 0x5a, 0xd2, 0x4b, 19);    // DEVPROP_TYPE_STRING_LIST
433 const DEVPKEY_DeviceClass_LowerFilters = DEFINE_DEVPROPKEY!(0x4321918b, 0xf69e, 0x470d, 0xa5, 0xde, 0x4d, 0x88, 0xc7, 0x5a, 0xd2, 0x4b, 20);    // DEVPROP_TYPE_STRING_LIST
434 const DEVPKEY_DeviceClass_Security = DEFINE_DEVPROPKEY!(0x4321918b, 0xf69e, 0x470d, 0xa5, 0xde, 0x4d, 0x88, 0xc7, 0x5a, 0xd2, 0x4b, 25);    // DEVPROP_TYPE_SECURITY_DESCRIPTOR
435 const DEVPKEY_DeviceClass_SecuritySDS = DEFINE_DEVPROPKEY!(0x4321918b, 0xf69e, 0x470d, 0xa5, 0xde, 0x4d, 0x88, 0xc7, 0x5a, 0xd2, 0x4b, 26);    // DEVPROP_TYPE_SECURITY_DESCRIPTOR_STRING
436 const DEVPKEY_DeviceClass_DevType = DEFINE_DEVPROPKEY!(0x4321918b, 0xf69e, 0x470d, 0xa5, 0xde, 0x4d, 0x88, 0xc7, 0x5a, 0xd2, 0x4b, 27);    // DEVPROP_TYPE_UINT32
437 const DEVPKEY_DeviceClass_Exclusive = DEFINE_DEVPROPKEY!(0x4321918b, 0xf69e, 0x470d, 0xa5, 0xde, 0x4d, 0x88, 0xc7, 0x5a, 0xd2, 0x4b, 28);    // DEVPROP_TYPE_BOOLEAN
438 const DEVPKEY_DeviceClass_Characteristics = DEFINE_DEVPROPKEY!(0x4321918b, 0xf69e, 0x470d, 0xa5, 0xde, 0x4d, 0x88, 0xc7, 0x5a, 0xd2, 0x4b, 29);    // DEVPROP_TYPE_UINT32
439 
440 //
441 // Device setup class properties
442 //
443 const DEVPKEY_DeviceClass_Name = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 2);      // DEVPROP_TYPE_STRING
444 const DEVPKEY_DeviceClass_ClassName = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 3);      // DEVPROP_TYPE_STRING
445 const DEVPKEY_DeviceClass_Icon = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 4);      // DEVPROP_TYPE_STRING
446 const DEVPKEY_DeviceClass_ClassInstaller = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 5);      // DEVPROP_TYPE_STRING
447 const DEVPKEY_DeviceClass_PropPageProvider = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 6);      // DEVPROP_TYPE_STRING
448 const DEVPKEY_DeviceClass_NoInstallClass = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 7);      // DEVPROP_TYPE_BOOLEAN
449 const DEVPKEY_DeviceClass_NoDisplayClass = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 8);      // DEVPROP_TYPE_BOOLEAN
450 const DEVPKEY_DeviceClass_SilentInstall = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 9);      // DEVPROP_TYPE_BOOLEAN
451 const DEVPKEY_DeviceClass_NoUseClass = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 10);     // DEVPROP_TYPE_BOOLEAN
452 const DEVPKEY_DeviceClass_DefaultService = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 11);     // DEVPROP_TYPE_STRING
453 const DEVPKEY_DeviceClass_IconPath = DEFINE_DEVPROPKEY!(0x259abffc, 0x50a7, 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66, 12);     // DEVPROP_TYPE_STRING_LIST
454 
455 const DEVPKEY_DeviceClass_DHPRebalanceOptOut = DEFINE_DEVPROPKEY!(0xd14d3ef3, 0x66cf, 0x4ba2, 0x9d, 0x38, 0x0d, 0xdb, 0x37, 0xab, 0x47, 0x01, 2);    // DEVPROP_TYPE_BOOLEAN
456 
457 //
458 // Other Device setup class properties
459 //
460 const DEVPKEY_DeviceClass_ClassCoInstallers = DEFINE_DEVPROPKEY!(0x713d1703, 0xa2e2, 0x49f5, 0x92, 0x14, 0x56, 0x47, 0x2e, 0xf3, 0xda, 0x5c, 2);     // DEVPROP_TYPE_STRING_LIST
461 
462 
463 //
464 // Device interface properties
465 //
466 const DEVPKEY_DeviceInterface_FriendlyName = DEFINE_DEVPROPKEY!(0x026e516e, 0xb814, 0x414b, 0x83, 0xcd, 0x85, 0x6d, 0x6f, 0xef, 0x48, 0x22, 2);     // DEVPROP_TYPE_STRING
467 const DEVPKEY_DeviceInterface_Enabled = DEFINE_DEVPROPKEY!(0x026e516e, 0xb814, 0x414b, 0x83, 0xcd, 0x85, 0x6d, 0x6f, 0xef, 0x48, 0x22, 3);     // DEVPROP_TYPE_BOOLEAN
468 const DEVPKEY_DeviceInterface_ClassGuid = DEFINE_DEVPROPKEY!(0x026e516e, 0xb814, 0x414b, 0x83, 0xcd, 0x85, 0x6d, 0x6f, 0xef, 0x48, 0x22, 4);     // DEVPROP_TYPE_GUID
469 
470 
471 //
472 // Device interface class properties
473 //
474 const DEVPKEY_DeviceInterfaceClass_DefaultInterface = DEFINE_DEVPROPKEY!(0x14c83a99, 0x0b3f, 0x44b7, 0xbe, 0x4c, 0xa1, 0x78, 0xd3, 0x99, 0x05, 0x64, 2); // DEVPROP_TYPE_STRING
475 
476 //
477 // DeviceDisplay properties that can be set on a devnode
478 //
479 const DEVPKEY_DeviceDisplay_IsShowInDisconnectedState = DEFINE_DEVPROPKEY!(0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57, 0x44); // DEVPROP_TYPE_BOOLEAN
480 const DEVPKEY_DeviceDisplay_IsNotInterestingForDisplay = DEFINE_DEVPROPKEY!(0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57, 0x4a); // DEVPROP_TYPE_BOOLEAN
481 const DEVPKEY_DeviceDisplay_Category = DEFINE_DEVPROPKEY!(0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57, 0x5a); // DEVPROP_TYPE_STRING_LIST
482 const DEVPKEY_DeviceDisplay_UnpairUninstall = DEFINE_DEVPROPKEY!(0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57, 0x62); // DEVPROP_TYPE_BOOLEAN
483 const DEVPKEY_DeviceDisplay_RequiresUninstallElevation = DEFINE_DEVPROPKEY!(0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57, 0x63); // DEVPROP_TYPE_BOOLEAN
484 const DEVPKEY_DeviceDisplay_AlwaysShowDeviceAsConnected = DEFINE_DEVPROPKEY!(0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57, 0x65); // DEVPROP_TYPE_BOOLEAN
485 
486 alias REFPROPERTYKEY = ref const(PROPERTYKEY);
487 alias REFPROPVARIANT = ref PROPVARIANT;
488 
489 enum ERole //__MIDL___MIDL_itf_mmdeviceapi_0000_0000_0002
490 {	
491     eConsole	= 0,
492     eMultimedia	= ( eConsole + 1 ) ,
493     eCommunications	= ( eMultimedia + 1 ) ,
494     ERole_enum_count	= ( eCommunications + 1 ) 
495 }
496 
497 enum EDataFlow //__MIDL___MIDL_itf_mmdeviceapi_0000_0000_0001
498 {	
499     eRender	= 0,
500     eCapture	= ( eRender + 1 ) ,
501     eAll	= ( eCapture + 1 ) ,
502     EDataFlow_enum_count	= ( eAll + 1 ) 
503 }
504 
505 enum DEVICE_STATE_ACTIVE      = 0x00000001;
506 enum DEVICE_STATE_DISABLED    = 0x00000002;
507 enum DEVICE_STATE_NOTPRESENT  = 0x00000004;
508 enum DEVICE_STATE_UNPLUGGED   = 0x00000008;
509 enum DEVICE_STATEMASK_ALL     = 0x0000000f;
510 
511 
512 /** WASAPI Interfaces */
513 
514 const IID IID_IPropertyStore = makeGuid!"886d8eeb-8cf2-4446-8d02-cdba1dbdcf99";
515 interface IPropertyStore : IUnknown {
516     HRESULT GetCount( 
517             /* [out] */ DWORD *cProps);
518 
519     HRESULT GetAt( 
520             /* [in] */ DWORD iProp,
521             /* [out] */ PROPERTYKEY *pkey);
522 
523     HRESULT GetValue( 
524             /* [in] */ const ref PROPERTYKEY key,
525             /* [out] */ out PROPVARIANT pv);
526 
527     HRESULT SetValue( 
528             /* [in] */ const ref PROPERTYKEY key,
529             /* [in] */ out PROPVARIANT propvar);
530 
531     HRESULT Commit();
532 }
533 
534 const IID IID_IMMDeviceCollection = makeGuid!"0BD7A1BE-7A1A-44DB-8397-CC5392387B5E";
535 interface IMMDeviceCollection : IUnknown {
536     HRESULT GetCount( 
537             /* [out] */ 
538             out UINT pcDevices);
539 
540     HRESULT Item( 
541             /* [in] */ 
542             UINT nDevice,
543             /* [out] */ 
544             out IMMDevice ppDevice);
545 }
546 
547 const IID IID_IMMDevice = makeGuid!"D666063F-1587-4E43-81F1-B948E807363F";
548 interface IMMDevice : IUnknown {
549     HRESULT Activate( 
550             /* [in] */ 
551             const ref IID iid,
552             /* [in] */ 
553             DWORD dwClsCtx,
554             /* [unique][in] */ 
555             PROPVARIANT *pActivationParams,
556             /* [iid_is][out] */ 
557             void ** ppInterface);
558 
559     HRESULT OpenPropertyStore( 
560             /* [in] */ 
561             DWORD stgmAccess,
562             /* [out] */ 
563             out IPropertyStore ppProperties);
564 
565     HRESULT GetId( 
566             /* [out] */ 
567             out LPWSTR ppstrId);
568 
569     HRESULT GetState( 
570             /* [out] */ 
571             out DWORD pdwState);
572 }
573 
574 
575 const IID IID_IMMNotificationClient = makeGuid!"7991EEC9-7E89-4D85-8390-6C703CEC60C0";
576 interface IMMNotificationClient : IUnknown {
577     HRESULT OnDeviceStateChanged( 
578             /* [annotation][in] */ 
579             LPCWSTR pwstrDeviceId,
580             /* [annotation][in] */ 
581             DWORD dwNewState);
582 
583     HRESULT OnDeviceAdded( 
584             /* [annotation][in] */ 
585             LPCWSTR pwstrDeviceId);
586 
587     HRESULT OnDeviceRemoved( 
588             /* [annotation][in] */ 
589             LPCWSTR pwstrDeviceId);
590 
591     HRESULT OnDefaultDeviceChanged( 
592             /* [annotation][in] */ 
593             EDataFlow flow,
594             /* [annotation][in] */ 
595             ERole role,
596             /* [annotation][in] */ 
597             LPCWSTR pwstrDefaultDeviceId);
598 
599     HRESULT OnPropertyValueChanged( 
600             /* [annotation][in] */ 
601             LPCWSTR pwstrDeviceId,
602             /* [annotation][in] */ 
603             const PROPERTYKEY key);
604 }
605 
606 const IID IID_IMMEndpoint = makeGuid!"1BE09788-6894-4089-8586-9A2A6C265AC5";
607 interface IMMEndpoint : IUnknown {
608     HRESULT GetDataFlow( 
609         /* [annotation][out] */ 
610         out EDataFlow pDataFlow);
611 }
612 
613 alias REFERENCE_TIME = long;
614 
615 enum AUDCLNT_SHAREMODE
616 {
617     AUDCLNT_SHAREMODE_SHARED,
618     AUDCLNT_SHAREMODE_EXCLUSIVE
619 }
620 
621 enum AUDCLNT_STREAMFLAGS_CROSSPROCESS             = 0x00010000;
622 enum AUDCLNT_STREAMFLAGS_LOOPBACK                 = 0x00020000;
623 enum AUDCLNT_STREAMFLAGS_EVENTCALLBACK            = 0x00040000;
624 enum AUDCLNT_STREAMFLAGS_NOPERSIST                = 0x00080000;
625 enum AUDCLNT_STREAMFLAGS_RATEADJUST               = 0x00100000;
626 
627 const IID IID_IAudioClient = makeGuid!"1CB9AD4C-DBFA-4c32-B178-C2F568A703B2";
628 interface IAudioClient : IUnknown {
629     HRESULT Initialize( 
630             /* [annotation][in] */ 
631             AUDCLNT_SHAREMODE ShareMode,
632             /* [annotation][in] */ 
633             DWORD StreamFlags,
634             /* [annotation][in] */ 
635             REFERENCE_TIME hnsBufferDuration,
636             /* [annotation][in] */ 
637             REFERENCE_TIME hnsPeriodicity,
638             /* [annotation][in] */ 
639             const WAVEFORMATEX *pFormat,
640             /* [annotation][in] */ 
641             LPCGUID AudioSessionGuid);
642 
643     HRESULT GetBufferSize( 
644             /* [annotation][out] */ 
645             out UINT32 pNumBufferFrames);
646 
647     HRESULT GetStreamLatency( 
648             /* [annotation][out] */ 
649             out REFERENCE_TIME phnsLatency);
650 
651     HRESULT GetCurrentPadding( 
652             /* [annotation][out] */ 
653             out UINT32 pNumPaddingFrames);
654 
655     HRESULT IsFormatSupported( 
656             /* [annotation][in] */ 
657             AUDCLNT_SHAREMODE ShareMode,
658             /* [annotation][in] */ 
659             const WAVEFORMATEX *pFormat,
660             /* [unique][annotation][out] */ 
661             WAVEFORMATEX **ppClosestMatch);
662 
663     HRESULT GetMixFormat( 
664             /* [annotation][out] */ 
665             out WAVEFORMATEX *ppDeviceFormat);
666 
667     HRESULT GetDevicePeriod( 
668             /* [annotation][out] */ 
669             out REFERENCE_TIME phnsDefaultDevicePeriod,
670             /* [annotation][out] */ 
671             out REFERENCE_TIME phnsMinimumDevicePeriod);
672 
673     HRESULT Start();
674 
675     HRESULT Stop();
676 
677     HRESULT Reset();
678 
679     HRESULT SetEventHandle( /* [in] */ HANDLE eventHandle);
680 
681     HRESULT GetService( 
682             /* [annotation][in] */ 
683             const ref IID riid,
684             /* [annotation][iid_is][out] */ 
685             void **ppv);
686 }
687 
688 enum AUDIO_STREAM_CATEGORY
689 {
690     AudioCategory_Other = 0,
691     AudioCategory_ForegroundOnlyMedia = 1,
692     AudioCategory_BackgroundCapableMedia = 2,
693     AudioCategory_Communications = 3,
694     AudioCategory_Alerts = 4,
695     AudioCategory_SoundEffects = 5,
696     AudioCategory_GameEffects = 6,
697     AudioCategory_GameMedia = 7,
698     AudioCategory_GameChat = 8,
699     AudioCategory_Speech = 9,
700     AudioCategory_Movie = 10,
701     AudioCategory_Media = 11,
702 }
703 
704 enum AUDCLNT_BUFFERFLAGS
705 {
706     AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY	= 0x1,
707     AUDCLNT_BUFFERFLAGS_SILENT	= 0x2,
708     AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR	= 0x4
709 }
710 
711 struct AudioClientProperties
712 {
713     UINT32 cbSize;
714     BOOL bIsOffload;
715     AUDIO_STREAM_CATEGORY eCategory;
716     AUDCLNT_STREAMOPTIONS Options;
717 }
718 
719 enum AUDCLNT_STREAMOPTIONS
720 {
721     AUDCLNT_STREAMOPTIONS_NONE	= 0,
722     AUDCLNT_STREAMOPTIONS_RAW	= 0x1,
723     AUDCLNT_STREAMOPTIONS_MATCH_FORMAT	= 0x2
724 }
725 
726 //AvSetMmThreadCharacteristics
727 //extern HANDLE AvSetMmThreadCharacteristicsA (
728 //                               immutable (char) * TaskName,
729 //                               out DWORD TaskIndex
730 //                               );
731 //extern BOOL AvRevertMmThreadCharacteristics (
732 //                                 HANDLE AvrtHandle
733 //                                 );
734 
735 private {
736     alias da_AvSetMmThreadCharacteristicsA = HANDLE function(immutable (char) * TaskName, out DWORD TaskIndex);
737     alias da_AvRevertMmThreadCharacteristics = BOOL function(HANDLE AvrtHandle);
738     __gshared da_AvSetMmThreadCharacteristicsA AvSetMmThreadCharacteristicsA;
739     __gshared da_AvRevertMmThreadCharacteristics AvRevertMmThreadCharacteristics;
740 
741     __gshared bool avrtDllLoaded;
742 
743     void loadAvrt() {
744         if (avrtDllLoaded)
745             return;
746         avrtDllLoaded = true;
747         HMODULE hlib = LoadLibraryA("Avrt.dll");
748         if (hlib) {
749             AvSetMmThreadCharacteristicsA = cast(da_AvSetMmThreadCharacteristicsA) GetProcAddress( hlib, "AvSetMmThreadCharacteristicsA");
750             AvRevertMmThreadCharacteristics = cast(da_AvRevertMmThreadCharacteristics) GetProcAddress( hlib, "AvRevertMmThreadCharacteristics");
751         }
752     }
753 }
754 
755 /**
756     Temporary boost thread priority for real time audio.
757 
758     Use returned value to restore thread priority - pass it to restoreThreadPriority.
759   */
760 void * setHighThreadPriority() {
761     void * handle = null;
762     loadAvrt();
763     DWORD taskIndex;
764     if (AvSetMmThreadCharacteristicsA)
765         handle = cast(void*)AvSetMmThreadCharacteristicsA("Pro Audio", taskIndex);
766     return handle;
767 }
768 
769 /**
770     Restore normal thread priority.
771 */
772 void restoreThreadPriority(void * handle) {
773     if (!handle)
774         return;
775     loadAvrt();
776     if (AvRevertMmThreadCharacteristics)
777         AvRevertMmThreadCharacteristics(cast(HANDLE)handle);
778 }
779 
780 const IID IID_IAudioClient2 = makeGuid!"726778CD-F60A-4eda-82DE-E47610CD78AA";
781 interface IAudioClient2 : IAudioClient {
782     HRESULT IsOffloadCapable( 
783             /* [annotation][in] */ 
784             AUDIO_STREAM_CATEGORY Category,
785             /* [annotation][out] */ 
786             out BOOL pbOffloadCapable);
787 
788     HRESULT SetClientProperties( 
789             /* [annotation][in] */ 
790             const ref AudioClientProperties pProperties);
791 
792     HRESULT GetBufferSizeLimits( 
793             /* [annotation][in] */ 
794             const WAVEFORMATEX *pFormat,
795             /* [annotation][in] */ 
796             BOOL bEventDriven,
797             /* [annotation][out] */ 
798             out REFERENCE_TIME phnsMinBufferDuration,
799             /* [annotation][out] */ 
800             out REFERENCE_TIME phnsMaxBufferDuration);
801 }
802 
803 const IID IID_IAudioClient3 = makeGuid!"7ED4EE07-8E67-4CD4-8C1A-2B7A5987AD42";
804 interface IAudioClient3 : IAudioClient2 {
805     HRESULT GetSharedModeEnginePeriod( 
806             /* [annotation][in] */ 
807             const WAVEFORMATEX *pFormat,
808             /* [annotation][out] */ 
809             out UINT32 pDefaultPeriodInFrames,
810             /* [annotation][out] */ 
811             out UINT32 pFundamentalPeriodInFrames,
812             /* [annotation][out] */ 
813             out UINT32 pMinPeriodInFrames,
814             /* [annotation][out] */ 
815             out UINT32 pMaxPeriodInFrames);
816 
817     HRESULT GetCurrentSharedModeEnginePeriod( 
818             /* [unique][annotation][out] */ 
819             out WAVEFORMATEX *ppFormat,
820             /* [annotation][out] */ 
821             out UINT32 pCurrentPeriodInFrames);
822 
823     HRESULT InitializeSharedAudioStream( 
824             /* [annotation][in] */ 
825             DWORD StreamFlags,
826             /* [annotation][in] */ 
827             UINT32 PeriodInFrames,
828             /* [annotation][in] */ 
829             const WAVEFORMATEX *pFormat,
830             /* [annotation][in] */ 
831             LPCGUID AudioSessionGuid);
832 }
833 
834 const IID IID_IAudioRenderClient = makeGuid!"F294ACFC-3146-4483-A7BF-ADDCA7C260E2";
835 interface IAudioRenderClient : IUnknown {
836     HRESULT GetBuffer( 
837             /* [annotation][in] */ 
838             UINT32 NumFramesRequested,
839             /* [annotation][out] */ //_Outptr_result_buffer_(_Inexpressible_("NumFramesRequested * pFormat->nBlockAlign"))  
840             out BYTE *ppData);
841 
842     HRESULT ReleaseBuffer( 
843             /* [annotation][in] */ 
844             UINT32 NumFramesWritten,
845             /* [annotation][in] */ 
846             DWORD dwFlags);
847 }
848 
849 const IID IID_IMMDeviceEnumerator = makeGuid!"A95664D2-9614-4F35-A746-DE8DB63617E6";
850 const CLSID CLSID_MMDeviceEnumerator = makeGuid!"BCDE0395-E52F-467C-8E3D-C4579291692E";
851 interface IMMDeviceEnumerator : IUnknown {
852     HRESULT EnumAudioEndpoints( 
853             /* [in] */ 
854             EDataFlow dataFlow,
855             /* [in] */ 
856             DWORD dwStateMask,
857             /* [out] */ 
858             out IMMDeviceCollection ppDevices);
859     
860     HRESULT GetDefaultAudioEndpoint( 
861             /* [in] */ 
862             EDataFlow dataFlow,
863             /* [in] */ 
864             ERole role,
865             /* [out] */ 
866             out IMMDevice ppEndpoint);
867     
868     HRESULT GetDevice( 
869             /*  */ 
870             LPCWSTR pwstrId,
871             /* [out] */ 
872             IMMDevice *ppDevice);
873     
874     HRESULT RegisterEndpointNotificationCallback( 
875             /* [in] */ 
876             IMMNotificationClient pClient);
877     
878     HRESULT UnregisterEndpointNotificationCallback( 
879             /* [in] */ 
880             IMMNotificationClient pClient);
881 }
882 
883 // Audio Capture
884 
885 const IID IID_IAudioCaptureClient = makeGuid!"C8ADBD64-E71E-48a0-A4DE-185C395CD317";
886 interface IAudioCaptureClient : IUnknown
887 {
888 public:
889     HRESULT GetBuffer( 
890         /* [annotation][out] */ 
891         out BYTE *ppData,
892         /* [annotation][out] */ 
893         out UINT32 pNumFramesToRead,
894         /* [annotation][out] */ 
895         out DWORD pdwFlags,
896         /* [annotation][unique][out] */ 
897         UINT64 *pu64DevicePosition,
898         /* [annotation][unique][out] */ 
899         UINT64 *pu64QPCPosition);
900         
901     HRESULT ReleaseBuffer( 
902         /* [annotation][in] */ 
903         UINT32 NumFramesRead);
904         
905     HRESULT GetNextPacketSize( 
906         /* [annotation][out] */ 
907         out UINT32 pNumFramesInNextPacket);
908         
909 }
910 
911 
912 
913 // endpointvolume.h
914 
915 struct AUDIO_VOLUME_NOTIFICATION_DATA
916 {
917     GUID guidEventContext;
918     BOOL bMuted;
919     float fMasterVolume;
920     UINT nChannels;
921     float[1] afChannelVolumes;
922 }
923 
924 const IID IID_IAudioEndpointVolumeCallback = makeGuid!"657804FA-D6AD-4496-8A60-352752AF4F89";
925 interface IAudioEndpointVolumeCallback : IUnknown
926 {
927     HRESULT OnNotify(AUDIO_VOLUME_NOTIFICATION_DATA * pNotify);
928 }
929 
930 const IID IID_IAudioEndpointVolume = makeGuid!"5CDF2C82-841E-4546-9722-0CF74078229A";
931 interface IAudioEndpointVolume : IUnknown
932 {
933 public:
934     HRESULT RegisterControlChangeNotify( 
935             /* [annotation][in] */ 
936             IAudioEndpointVolumeCallback *pNotify);
937 
938     HRESULT UnregisterControlChangeNotify( 
939             /* [annotation][in] */ 
940             IAudioEndpointVolumeCallback *pNotify);
941 
942     HRESULT GetChannelCount( 
943             /* [annotation][out] */ 
944             out UINT pnChannelCount);
945 
946     HRESULT SetMasterVolumeLevel( 
947             /* [annotation][in] */ 
948             float fLevelDB,
949             /* [unique][in] */ LPCGUID pguidEventContext);
950 
951     HRESULT SetMasterVolumeLevelScalar( 
952             /* [annotation][in] */ 
953             float fLevel,
954             /* [unique][in] */ ref const(GUID) pguidEventContext);
955 
956     HRESULT GetMasterVolumeLevel( 
957             /* [annotation][out] */ 
958             out float pfLevelDB);
959 
960     HRESULT GetMasterVolumeLevelScalar( 
961             /* [annotation][out] */ 
962             out float pfLevel);
963 
964     HRESULT SetChannelVolumeLevel( 
965             /* [annotation][in] */ 
966             UINT nChannel,
967             float fLevelDB,
968             /* [unique][in] */ LPCGUID pguidEventContext);
969 
970     HRESULT SetChannelVolumeLevelScalar( 
971             /* [annotation][in] */ 
972             UINT nChannel,
973             float fLevel,
974             /* [unique][in] */ LPCGUID pguidEventContext);
975 
976     HRESULT GetChannelVolumeLevel( 
977             /* [annotation][in] */ 
978             UINT nChannel,
979             /* [annotation][out] */ 
980             out float pfLevelDB);
981 
982     HRESULT GetChannelVolumeLevelScalar( 
983             /* [annotation][in] */ 
984             UINT nChannel,
985             /* [annotation][out] */ 
986             out float pfLevel);
987 
988     HRESULT SetMute( 
989             /* [annotation][in] */ 
990             BOOL bMute,
991             /* [unique][in] */ ref const(GUID) pguidEventContext);
992 
993     HRESULT GetMute( 
994             /* [annotation][out] */ 
995             out  BOOL pbMute);
996 
997     HRESULT GetVolumeStepInfo( 
998             /* [annotation][out] */ 
999             out UINT pnStep,
1000             /* [annotation][out] */ 
1001             out UINT pnStepCount);
1002 
1003     HRESULT VolumeStepUp( 
1004             /* [unique][in] */ ref const(GUID) pguidEventContext);
1005 
1006     HRESULT VolumeStepDown( 
1007             /* [unique][in] */ ref const(GUID) pguidEventContext);
1008 
1009     HRESULT QueryHardwareSupport( 
1010             /* [annotation][out] */ 
1011             out DWORD pdwHardwareSupportMask);
1012 
1013     HRESULT GetVolumeRange( 
1014             /* [annotation][out] */ 
1015             out float pflVolumeMindB,
1016             /* [annotation][out] */ 
1017             out float pflVolumeMaxdB,
1018             /* [annotation][out] */ 
1019             out float pflVolumeIncrementdB);
1020 }
1021 
1022 
1023 extern HRESULT PropVariantClear(PROPVARIANT* pvar);
1024 
1025 extern HRESULT FreePropVariantArray(
1026                                     ULONG cVariants,
1027                                     PROPVARIANT* rgvars);
1028 
1029