Inline temporary variable.

This commit is contained in:
2022-11-15 00:20:20 +00:00
parent 2f6ef0c498
commit 47965f0584
7 changed files with 28 additions and 40 deletions

View File

@@ -93,9 +93,8 @@ static partial class Usb
// now we can get some more detailed information
var nRequiredSize = 0;
const int nBytes = BUFFER_SIZE;
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da))
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, BUFFER_SIZE, ref nRequiredSize, ref da))
{
host._controllerDevicePath = didd.DevicePath;
@@ -131,11 +130,10 @@ static partial class Usb
static string GetDescriptionByKeyName(string driverKeyName)
{
var ans = "";
const string devEnum = REGSTR_KEY_USB;
// Use the "enumerator form" of the SetupDiGetClassDevs API
// to generate a list of all USB devices
IntPtr h = SetupDiGetClassDevs(0, devEnum, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
IntPtr h = SetupDiGetClassDevs(0, REGSTR_KEY_USB, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
if(h == _invalidHandleValue)
return ans;
@@ -190,11 +188,10 @@ static partial class Usb
static string GetInstanceIdByKeyName(string driverKeyName)
{
var ans = "";
const string devEnum = REGSTR_KEY_USB;
// Use the "enumerator form" of the SetupDiGetClassDevs API
// to generate a list of all USB devices
IntPtr h = SetupDiGetClassDevs(0, devEnum, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
IntPtr h = SetupDiGetClassDevs(0, REGSTR_KEY_USB, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
if(h == _invalidHandleValue)
return ans;
@@ -227,9 +224,8 @@ static partial class Usb
// is it a match?
if(keyName == driverKeyName)
{
const int nBytes = BUFFER_SIZE;
var sb = new StringBuilder(nBytes);
SetupDiGetDeviceInstanceId(h, ref da, sb, nBytes, out requiredSize);
var sb = new StringBuilder(BUFFER_SIZE);
SetupDiGetDeviceInstanceId(h, ref da, sb, BUFFER_SIZE, out requiredSize);
ans = sb.ToString();
break;

View File

@@ -241,9 +241,8 @@ static partial class Usb
// now we can get some more detailed information
var nRequiredSize = 0;
const int nBytes = BUFFER_SIZE;
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da))
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, BUFFER_SIZE, ref nRequiredSize, ref da))
if(GetDeviceNumber(didd.DevicePath) == devNum)
{
// current InstanceID is at the "USBSTOR" level, so we
@@ -251,8 +250,8 @@ static partial class Usb
CM_Get_Parent(out IntPtr ptrPrevious, da.DevInst, 0);
// Now we get the InstanceID of the USB level device
IntPtr ptrInstanceBuf = Marshal.AllocHGlobal(nBytes);
CM_Get_Device_ID(ptrPrevious, ptrInstanceBuf, nBytes, 0);
nint ptrInstanceBuf = Marshal.AllocHGlobal(BUFFER_SIZE);
CM_Get_Device_ID(ptrPrevious, ptrInstanceBuf, BUFFER_SIZE, 0);
instanceId = Marshal.PtrToStringAuto(ptrInstanceBuf);
Marshal.FreeHGlobal(ptrInstanceBuf);