Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than setupapi, prefix the name with the module name and a period.
SetupDiGetDeviceInstanceId (setupapi)
.
C# Signature:
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool SetupDiGetDeviceInstanceId(
IntPtr DeviceInfoSet,
ref SP_DEVINFO_DATA DeviceInfoData,
StringBuilder DeviceInstanceId,
int DeviceInstanceIdSize,
out int RequiredSize
);
VB Signature:
Declare Function SetupDiGetDeviceInstanceId Lib "setupapi.dll" (TODO) As TODO
WINSETUPAPI BOOL WINAPI SetupDiGetDeviceInstanceId(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
OUT PTSTR DeviceInstanceId,
IN DWORD DeviceInstanceIdSize,
OUT PDWORD RequiredSize OPTIONAL
);
// 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);
if (h.ToInt32() != INVALID_HANDLE_VALUE)
{
IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE);
string KeyName;
bool Success = true;
int i = 0;
while (Success)
{
// create a Device Interface Data structure
SP_DEVINFO_DATA da = new SP_DEVINFO_DATA();
da.cbSize = Marshal.SizeOf(da);
// start the enumeration
Success = SetupDiEnumDeviceInfo(h, i, ref da);
if (Success)
{
int RequiredSize = 0;
int RegType = REG_SZ;
KeyName = "";
if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref RegType, ptrBuf, BUFFER_SIZE, ref RequiredSize))
{
KeyName = Marshal.PtrToStringAuto(ptrBuf);
}
// is it a match?
if (KeyName == DriverKeyName)
{
int nBytes = BUFFER_SIZE;
StringBuilder sb = new StringBuilder(nBytes);
SetupDiGetDeviceInstanceId(h, ref da, sb, nBytes, out RequiredSize);
ans = sb.ToString();
break;
}
}
i++;
}
Marshal.FreeHGlobal(ptrBuf);
SetupDiDestroyDeviceInfoList(h);
}
return ans;
}
The SetupDiGetDeviceInstanceId function retrieves the device instance ID that is associated with a device information element.
defines a device instance that is a member of the device information set
4/21/2018 9:30:32 AM - 172.56.32.78
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).