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