2626
2727namespace Windows . Win32 . System . SystemServices
2828{
29- internal partial struct DEVPROPKEY
29+ partial struct DEVPROPKEY
3030 {
3131 /// <summary>
3232 /// *HACK*
3333 ///
3434 /// CsWin32 confuses PROPERTYKEY and DEVPROPKEY, which are in fact the exact same structure.
35- /// This is a c++-like "reinterpret_cast".
35+ /// This is an implicit c++-like "reinterpret_cast".
3636 /// </summary>
37- public static ref DEVPROPKEY From ( in PROPERTYKEY propertyKey )
37+ public static implicit operator DEVPROPKEY ( in PROPERTYKEY propertyKey )
3838 {
39- return ref Unsafe . As < PROPERTYKEY , DEVPROPKEY > ( ref Unsafe . AsRef ( in propertyKey ) ) ;
39+ return Unsafe . As < PROPERTYKEY , DEVPROPKEY > ( ref Unsafe . AsRef ( propertyKey ) ) ;
4040 }
4141 }
4242}
@@ -129,13 +129,13 @@ public static bool IsUsbHub(string deviceInstanceId)
129129 return EnumDeviceInterfaces ( hubs , Constants . GUID_DEVINTERFACE_USB_HUB ) . Any ( ) ;
130130 }
131131
132- public static uint GetDevicePropertyUInt32 ( SafeDeviceInfoSetHandle deviceInfoSet , in SP_DEVINFO_DATA devInfoData , in PROPERTYKEY propertyKey )
132+ public static uint GetDevicePropertyUInt32 ( SafeDeviceInfoSetHandle deviceInfoSet , in SP_DEVINFO_DATA devInfoData , in DEVPROPKEY devPropKey )
133133 {
134134 unsafe
135135 {
136136 uint value ;
137137 uint requiredSize ;
138- if ( ! PInvoke . SetupDiGetDeviceProperty ( deviceInfoSet . PInvokeHandle , in devInfoData , in DEVPROPKEY . From ( in propertyKey ) , out var devPropType , ( byte * ) & value , 4 , & requiredSize , 0 ) )
138+ if ( ! PInvoke . SetupDiGetDeviceProperty ( deviceInfoSet . PInvokeHandle , devInfoData , devPropKey , out var devPropType , ( byte * ) & value , 4 , & requiredSize , 0 ) )
139139 {
140140 throw new Win32Exception ( "SetupDiGetDeviceProperty" ) ;
141141 }
@@ -151,12 +151,12 @@ public static uint GetDevicePropertyUInt32(SafeDeviceInfoSetHandle deviceInfoSet
151151 }
152152 }
153153
154- public static string GetDevicePropertyString ( SafeDeviceInfoSetHandle deviceInfoSet , in SP_DEVINFO_DATA devInfoData , in PROPERTYKEY propertyKey )
154+ public static string GetDevicePropertyString ( SafeDeviceInfoSetHandle deviceInfoSet , in SP_DEVINFO_DATA devInfoData , in DEVPROPKEY devPropKey )
155155 {
156156 unsafe
157157 {
158158 uint requiredSize ;
159- if ( PInvoke . SetupDiGetDeviceProperty ( deviceInfoSet . PInvokeHandle , in devInfoData , in DEVPROPKEY . From ( in propertyKey ) , out var devPropType , null , 0 , & requiredSize , 0 ) )
159+ if ( PInvoke . SetupDiGetDeviceProperty ( deviceInfoSet . PInvokeHandle , devInfoData , devPropKey , out var devPropType , null , 0 , & requiredSize , 0 ) )
160160 {
161161 throw new UnexpectedResultException ( $ "SetupDiGetDeviceProperty succeeded, expected to fail with { WIN32_ERROR . ERROR_INSUFFICIENT_BUFFER } ") ;
162162 }
@@ -174,7 +174,7 @@ public static string GetDevicePropertyString(SafeDeviceInfoSetHandle deviceInfoS
174174 }
175175 var output = stackalloc char [ ( int ) requiredSize / 2 ] ;
176176 uint requiredSize2 ;
177- if ( ! PInvoke . SetupDiGetDeviceProperty ( deviceInfoSet . PInvokeHandle , in devInfoData , in DEVPROPKEY . From ( in propertyKey ) , out devPropType , ( byte * ) output , requiredSize , & requiredSize2 , 0 ) )
177+ if ( ! PInvoke . SetupDiGetDeviceProperty ( deviceInfoSet . PInvokeHandle , devInfoData , devPropKey , out devPropType , ( byte * ) output , requiredSize , & requiredSize2 , 0 ) )
178178 {
179179 throw new Win32Exception ( "SetupDiGetDeviceProperty" ) ;
180180 }
@@ -194,21 +194,21 @@ public static string GetDevicePropertyString(SafeDeviceInfoSetHandle deviceInfoS
194194 }
195195 }
196196
197- public static string GetDevicePropertyString ( string deviceInstanceId , in PROPERTYKEY devPropKey )
197+ public static string GetDevicePropertyString ( string deviceInstanceId , in DEVPROPKEY devPropKey )
198198 {
199199 using var deviceInfoSet = SetupDiGetClassDevs ( null , deviceInstanceId , default , Constants . DIGCF_DEVICEINTERFACE | Constants . DIGCF_ALLCLASSES | Constants . DIGCF_PRESENT ) ;
200200 var devinfoData = EnumDeviceInfo ( deviceInfoSet ) . Single ( ) ;
201- return GetDevicePropertyString ( deviceInfoSet , devinfoData , in devPropKey ) ;
201+ return GetDevicePropertyString ( deviceInfoSet , devinfoData , devPropKey ) ;
202202 }
203203
204- public static void SetDevicePropertyString ( SafeDeviceInfoSetHandle deviceInfoSet , in SP_DEVINFO_DATA devInfoData , in PROPERTYKEY propertyKey , string ? value )
204+ public static void SetDevicePropertyString ( SafeDeviceInfoSetHandle deviceInfoSet , in SP_DEVINFO_DATA devInfoData , in DEVPROPKEY devPropKey , string ? value )
205205 {
206206 unsafe
207207 {
208208 if ( value is null )
209209 {
210210 // This will delete the property
211- if ( ! PInvoke . SetupDiSetDeviceProperty ( deviceInfoSet . PInvokeHandle , in devInfoData , in DEVPROPKEY . From ( in propertyKey ) , Constants . DEVPROP_TYPE_EMPTY , null , 0u , 0u ) )
211+ if ( ! PInvoke . SetupDiSetDeviceProperty ( deviceInfoSet . PInvokeHandle , devInfoData , devPropKey , Constants . DEVPROP_TYPE_EMPTY , null , 0u , 0u ) )
212212 {
213213 throw new Win32Exception ( "SetupDiSetDeviceProperty" ) ;
214214 }
@@ -219,11 +219,11 @@ public static void SetDevicePropertyString(SafeDeviceInfoSetHandle deviceInfoSet
219219 var buf = Encoding . Unicode . GetBytes ( value + '\0 ' ) ;
220220 fixed ( SP_DEVINFO_DATA * pInfoData = & devInfoData )
221221 {
222- fixed ( PROPERTYKEY * pPropKey = & propertyKey )
222+ fixed ( DEVPROPKEY * pDevPropKey = & devPropKey )
223223 {
224224 fixed ( byte * pBuf = buf )
225225 {
226- if ( ! PInvoke . SetupDiSetDeviceProperty ( deviceInfoSet . PInvokeHandle , pInfoData , ( DEVPROPKEY * ) pPropKey , Constants . DEVPROP_TYPE_STRING , pBuf , ( uint ) buf . Length , 0u ) )
226+ if ( ! PInvoke . SetupDiSetDeviceProperty ( deviceInfoSet . PInvokeHandle , pInfoData , pDevPropKey , Constants . DEVPROP_TYPE_STRING , pBuf , ( uint ) buf . Length , 0u ) )
227227 {
228228 throw new Win32Exception ( "SetupDiSetDeviceProperty" ) ;
229229 }
@@ -281,7 +281,7 @@ static bool EnumDeviceInterfaces(SafeDeviceInfoSetHandle deviceInfoSet, SP_DEVIN
281281 unsafe
282282 {
283283 interfaceData . cbSize = ( uint ) Marshal . SizeOf < SP_DEVICE_INTERFACE_DATA > ( ) ;
284- if ( PInvoke . SetupDiEnumDeviceInterfaces ( deviceInfoSet . PInvokeHandle , devInfoData , in interfaceClassGuid , index , out interfaceData ) )
284+ if ( PInvoke . SetupDiEnumDeviceInterfaces ( deviceInfoSet . PInvokeHandle , devInfoData , interfaceClassGuid , index , out interfaceData ) )
285285 {
286286 return true ;
287287 }
@@ -314,7 +314,7 @@ public static string GetDeviceInterfaceDetail(SafeDeviceInfoSetHandle deviceInfo
314314 unsafe
315315 {
316316 uint requiredSize ;
317- if ( PInvoke . SetupDiGetDeviceInterfaceDetail ( deviceInfoSet . PInvokeHandle , in interfaceData , null , 0 , & requiredSize , null ) )
317+ if ( PInvoke . SetupDiGetDeviceInterfaceDetail ( deviceInfoSet . PInvokeHandle , interfaceData , null , 0 , & requiredSize , null ) )
318318 {
319319 throw new UnexpectedResultException ( "SetupDiGetDeviceInterfaceDetail succeeded, expected to fail with ERROR_INSUFFICIENT_BUFFER" ) ;
320320 }
@@ -330,7 +330,7 @@ public static string GetDeviceInterfaceDetail(SafeDeviceInfoSetHandle deviceInfo
330330 var detailData = ( SP_DEVICE_INTERFACE_DETAIL_DATA_W * ) output ;
331331 detailData ->cbSize = ( uint ) Marshal . SizeOf < SP_DEVICE_INTERFACE_DETAIL_DATA_W > ( ) ;
332332 uint requiredSize2 ;
333- if ( ! PInvoke . SetupDiGetDeviceInterfaceDetail ( deviceInfoSet . PInvokeHandle , in interfaceData , detailData , requiredSize , & requiredSize2 , null ) )
333+ if ( ! PInvoke . SetupDiGetDeviceInterfaceDetail ( deviceInfoSet . PInvokeHandle , interfaceData , detailData , requiredSize , & requiredSize2 , null ) )
334334 {
335335 throw new Win32Exception ( "SetupDiGetDeviceInterfaceDetail" ) ;
336336 }
@@ -344,7 +344,7 @@ public static string GetDeviceInterfaceDetail(SafeDeviceInfoSetHandle deviceInfo
344344
345345 public static void GetBusId ( SafeDeviceInfoSetHandle deviceInfoSet , in SP_DEVINFO_DATA devInfoData , out BusId busId )
346346 {
347- var locationInfo = GetDevicePropertyString ( deviceInfoSet , devInfoData , in Constants . DEVPKEY_Device_LocationInfo ) ;
347+ var locationInfo = GetDevicePropertyString ( deviceInfoSet , devInfoData , Constants . DEVPKEY_Device_LocationInfo ) ;
348348 var match = Regex . Match ( locationInfo , "^Port_#([0-9]{4}).Hub_#([0-9]{4})$" , RegexOptions . IgnoreCase | RegexOptions . CultureInvariant ) ;
349349 if ( ! match . Success )
350350 {
0 commit comments