Beispiel #1
0
        private static string[] GetAllHIDInterFace()
        {
            var arrayList = new List <string>();

            try
            {
                var sYSTEM_INFO = default(Kernel32.SYSTEM_INFO);
                Kernel32.GetSystemInfo(out sYSTEM_INFO);
                bool flag = sYSTEM_INFO.sysInfoEx.wProcessorArchitecture == 9 || sYSTEM_INFO.sysInfoEx.wProcessorArchitecture == 6;
                Guid guid = default(Guid);
                HID.HidD_GetHidGuid(ref guid);
                var sP_DEVINFO_DATA = default(DM.SP_DEVINFO_DATA);
                sP_DEVINFO_DATA.cbSize = Marshal.SizeOf(sP_DEVINFO_DATA);
                var deviceInfoSet = DM.SetupDiGetClassDevs(ref guid, null, 0, 18u);
                if (!Environment.Is64BitOperatingSystem)
                {
                    throw new Exception(CMessages.GetLastWin32ErrorToString());
                }
                else if (-1L == deviceInfoSet.ToInt64())
                {
                    throw new Exception(CMessages.GetLastWin32ErrorToString());
                }
                uint num = 0;
                while (DM.SetupDiEnumDeviceInfo(deviceInfoSet, num, ref sP_DEVINFO_DATA))
                {
                    var sP_DEVICE_INTERFACE_DATA = default(DM.SP_DEVICE_INTERFACE_DATA);
                    sP_DEVICE_INTERFACE_DATA.cbSize = Marshal.SizeOf(sP_DEVICE_INTERFACE_DATA);
                    uint num2 = 0;
                    while (DM.SetupDiEnumDeviceInterfaces(deviceInfoSet, ref sP_DEVINFO_DATA, ref guid, num2++, ref sP_DEVICE_INTERFACE_DATA))
                    {
                        int num3 = 0;
                        if (!DM.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref sP_DEVICE_INTERFACE_DATA, IntPtr.Zero, 0, ref num3, IntPtr.Zero) && 122 != Marshal.GetLastWin32Error())
                        {
                            throw new Exception(CMessages.GetLastWin32ErrorToString());
                        }
                        int num4   = 0;
                        var intPtr = Marshal.AllocHGlobal(num3);
                        Marshal.WriteInt32(intPtr, flag ? 8 : (Marshal.SizeOf(0u) + Marshal.SystemDefaultCharSize));
                        if (!DM.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref sP_DEVICE_INTERFACE_DATA, intPtr, num3, ref num4, IntPtr.Zero))
                        {
                            throw new Exception(CMessages.GetLastWin32ErrorToString());
                        }
                        var ptr = new IntPtr(Environment.Is64BitOperatingSystem ? intPtr.ToInt64() + (long)Marshal.SizeOf(0u) : intPtr.ToInt32() + Marshal.SizeOf(0u));
                        arrayList.Add(Marshal.PtrToStringAuto(ptr));
                        Marshal.FreeHGlobal(intPtr);
                    }
                    num += 1;
                }
                DM.SetupDiDestroyDeviceInfoList(deviceInfoSet);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(arrayList.ToArray());
        }