LitDev.Engines.HIDDevice.GetDevicePath C# (CSharp) Method

GetDevicePath() private static method

Helper method to return the device path given a DeviceInterfaceData structure and an InfoSet handle. Used in 'FindDevice' so check that method out to see how to get an InfoSet handle and a DeviceInterfaceData.
private static GetDevicePath ( IntPtr hInfoSet, DeviceInterfaceData &oInterface ) : string
hInfoSet System.IntPtr Handle to the InfoSet
oInterface DeviceInterfaceData DeviceInterfaceData structure
return string
        private static string GetDevicePath(IntPtr hInfoSet, ref DeviceInterfaceData oInterface)
        {
            uint nRequiredSize = 0;
            DeviceInfoData da = new DeviceInfoData();
            da.Size = (uint)Marshal.SizeOf(da);
            // Get the device interface details
            if (!SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, IntPtr.Zero, 0, ref nRequiredSize, ref da))
            {
                DeviceInterfaceDetailData oDetail = new DeviceInterfaceDetailData();
                oDetail.Size = (IntPtr.Size == 4) ? 5 : 8;	// hardcoded to 5! Sorry, but this works and trying more future proof versions by setting the size to the struct sizeof failed miserably. If you manage to sort it, mail me! Thx

                if (SetupDiGetDeviceInterfaceDetail(hInfoSet, ref oInterface, ref oDetail, nRequiredSize, ref nRequiredSize, ref da))
                {
                    return oDetail.DevicePath;
                }
            }
            return null;
        }