SetupDiEnumDeviceInterfaces (setupapi)
Last changed: -24.135.125.153

.
Summary
Retrieve information about a device in a device information set.

C# Signature:

[DllImport(@"setupapi.dll", CharSet=CharSet.Auto, SetLastError = true)]
public static extern Boolean SetupDiEnumDeviceInterfaces(
   IntPtr hDevInfo,
   ref SP_DEVINFO_DATA devInfo,
   ref Guid interfaceClassGuid,
   UInt32 memberIndex,
   ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData
);

VB Signature:

Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (TODO) As TODO

User-Defined Types:

None.

Notes:

A call to SetupDiEnumDeviceInterfaces retrieves a pointer to a structure that identifies a specific device interface in the previously retrieved DeviceInfoSet array. The call specifies a device interface by passing an array index. To retrieve information about all of the device interfaces, an application can loop through the array, incrementing the array index until the function returns zero, indicating that there are no more interfaces. The GetLastError API function then returns No more data is available.

Tips & Tricks:

    [StructLayout(LayoutKind.Sequential)]
    public struct SP_DEVINFO_DATA
    {
        public uint cbSize;
        public Guid ClassGuid;
        public uint DevInst;
        public IntPtr Reserved;
    }

//You need to create a structure for the deviceInterfaceData like this....

    public struct SP_DEVICE_INTERFACE_DATA
    {
        public int cbSize;
        public Guid InterfaceClassGuid;
        public int Flags;
        public IntPtr RESERVED;
    }

//Then initialize the cbSize value like this in your calling method

SP_DEVICE_INTERFACE_DATA devData = new SP_DEVICE_INTERFACE_DATA();

devData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(devData);

// failure to do so will always return false (which is the value you'll also get if the device is not connected)

// Here's what the call looks like...

bool result = Win32Calls.SetupDiEnumDeviceInterfaces(ipDeviceHndl, iLU, ref DeviceGUID, 0, ref devData);

// The DeviceGUID parameter will be device dependant. Look in the Manufacturer's sdk or api for the correct guid for your device

Sample Code:

class Win32Calls
    {
    [DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern IntPtr SetupDiGetClassDevs(ref Guid classGuid, IntPtr enumerator, IntPtr hwndParent, UInt32 flags);
    [DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern Boolean SetupDiEnumDeviceInterfaces(IntPtr hDevInfo, IntPtr devInfo, ref Guid interfaceClassGuid, UInt32 memberIndex, ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData);

    }

Documentation