Skip to content

Commit c61db21

Browse files
committed
Bump CsWin32
- add implicit cast from PROPERTYKEY to DEVPROPKEY - remove unnecessary 'in'
1 parent db79f07 commit c61db21

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SPDX-License-Identifier: GPL-2.0-only
1414
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
1515
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
1616
<PackageVersion Include="System.Management" Version="5.0.0" />
17-
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.1.506-beta" />
17+
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.1.588-beta" />
1818

1919
<!-- Installer -->
2020
<PackageVersion Include="WiX" Version="3.11.2" />

UsbIpServer/ExportedDevice.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ static async Task<UsbConfigurationDescriptors> GetConfigurationDescriptor(Device
142142

143143
static async Task<ExportedDevice?> GetDevice(SafeDeviceInfoSetHandle deviceInfoSet, SP_DEVINFO_DATA devInfoData, CancellationToken cancellationToken)
144144
{
145-
var instanceId = GetDevicePropertyString(deviceInfoSet, devInfoData, in Constants.DEVPKEY_Device_InstanceId);
145+
var instanceId = GetDevicePropertyString(deviceInfoSet, devInfoData, Constants.DEVPKEY_Device_InstanceId);
146146
if (IsUsbHub(instanceId))
147147
{
148148
// device is itself a USB hub, which is not supported
149149
return null;
150150
}
151-
var parentId = GetDevicePropertyString(deviceInfoSet, devInfoData, in Constants.DEVPKEY_Device_Parent);
151+
var parentId = GetDevicePropertyString(deviceInfoSet, devInfoData, Constants.DEVPKEY_Device_Parent);
152152
if (!IsUsbHub(parentId))
153153
{
154154
// parent is not a USB hub (which it must be for this device to be supported)
@@ -159,7 +159,7 @@ static async Task<UsbConfigurationDescriptors> GetConfigurationDescriptor(Device
159159

160160
GetBusId(deviceInfoSet, devInfoData, out var busId);
161161

162-
var address = GetDevicePropertyUInt32(deviceInfoSet, devInfoData, in Constants.DEVPKEY_Device_Address);
162+
var address = GetDevicePropertyUInt32(deviceInfoSet, devInfoData, Constants.DEVPKEY_Device_Address);
163163
if (busId.Port != address)
164164
{
165165
throw new NotSupportedException($"DEVPKEY_Device_Address ({address}) does not match DEVPKEY_Device_LocationInfo ({busId.Port})");

UsbIpServer/Interop/UsbIp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static async Task<UsbIpIsoPacketDescriptor[]> ReadUsbIpIsoPacketDescripto
200200
public static byte[] ToBytes(this in UsbIpHeader header)
201201
{
202202
var bytes = new byte[Unsafe.SizeOf<UsbIpHeader>()];
203-
MemoryMarshal.Write(bytes, ref Unsafe.AsRef(in header));
203+
MemoryMarshal.Write(bytes, ref Unsafe.AsRef(header));
204204
MemoryMarshal.AsRef<UsbIpHeader>(bytes).ReverseEndianness();
205205
return bytes;
206206
}

UsbIpServer/Tools.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626

2727
namespace 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
{

UsbIpServer/VBoxUsbMon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async Task<DeviceFile> ClaimDeviceOnce(ExportedDevice device)
128128
// "VBoxUSB".
129129

130130
// Best effort, not really a problem if this fails.
131-
SetDevicePropertyString(deviceInfoSet, in infoData, in Constants.DEVPKEY_Device_FriendlyName, $"USBIP Shared Device {device.BusId}");
131+
SetDevicePropertyString(deviceInfoSet, infoData, Constants.DEVPKEY_Device_FriendlyName, $"USBIP Shared Device {device.BusId}");
132132
}
133133
catch (Win32Exception) { }
134134

0 commit comments

Comments
 (0)