コード例 #1
0
 internal static extern bool SetupDiEnumDeviceInterfaces(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, ref Guid InterfaceClassGuid, int MemberIndex, ref DeviceManagement.SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
コード例 #2
0
 internal static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr DeviceInfoSet, ref DeviceManagement.SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, IntPtr DeviceInterfaceDetailData, int DeviceInterfaceDetailDataSize, ref int RequiredSize, IntPtr DeviceInfoData);
コード例 #3
0
        internal eReturn EnumerateDevices(Guid geneaGuid, List <string> devicePathName)
        {
            int    RequiredSize  = 0;
            IntPtr num           = IntPtr.Zero;
            IntPtr DeviceInfoSet = new IntPtr();
            bool   flag1         = false;

            DeviceManagement.SP_DEVICE_INTERFACE_DATA DeviceInterfaceData = new DeviceManagement.SP_DEVICE_INTERFACE_DATA();
            bool    flag2    = false;
            eReturn eReturn1 = eReturn.FAILURE;
            eReturn eReturn2;

            try
            {
                DeviceInfoSet = DeviceManagement.SetupDiGetClassDevs(ref geneaGuid, IntPtr.Zero, IntPtr.Zero, 18);
                eReturn2      = eReturn.SUCCESS;
            }
            catch
            {
                eReturn2 = eReturn.FAILURE;
            }
            if (eReturn2 == eReturn.SUCCESS)
            {
                eReturn1 = eReturn.FAILURE;
                int MemberIndex = 0;
                try
                {
                    DeviceInterfaceData.cbSize = Marshal.SizeOf <DeviceManagement.SP_DEVICE_INTERFACE_DATA>(DeviceInterfaceData);
                    eReturn2 = eReturn.SUCCESS;
                }
                catch
                {
                    eReturn2 = eReturn.FAILURE;
                }
                if (eReturn2 == eReturn.SUCCESS)
                {
                    eReturn1 = eReturn.FAILURE;
                    do
                    {
                        try
                        {
                            flag2    = DeviceManagement.SetupDiEnumDeviceInterfaces(DeviceInfoSet, IntPtr.Zero, ref geneaGuid, MemberIndex, ref DeviceInterfaceData);
                            eReturn2 = eReturn.SUCCESS;
                        }
                        catch
                        {
                            eReturn2 = eReturn.FAILURE;
                        }
                        if (eReturn2 == eReturn.SUCCESS)
                        {
                            eReturn2 = eReturn.FAILURE;
                            if (!flag2)
                            {
                                flag1 = true;
                            }
                            else
                            {
                                try
                                {
                                    flag2 = DeviceManagement.SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, ref DeviceInterfaceData, IntPtr.Zero, 0, ref RequiredSize, IntPtr.Zero);
                                    num   = Marshal.AllocHGlobal(RequiredSize);
                                    Marshal.WriteInt32(num, IntPtr.Size == 4 ? 4 + Marshal.SystemDefaultCharSize : 8);
                                    flag2    = DeviceManagement.SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, ref DeviceInterfaceData, num, RequiredSize, ref RequiredSize, IntPtr.Zero);
                                    eReturn2 = eReturn.SUCCESS;
                                }
                                catch
                                {
                                    eReturn2 = eReturn.FAILURE;
                                }
                                if (eReturn2 == eReturn.SUCCESS)
                                {
                                    eReturn2 = eReturn.FAILURE;
                                    if (flag2)
                                    {
                                        IntPtr ptr = new IntPtr(num.ToInt32() + 4);
                                        devicePathName.Add(Marshal.PtrToStringAuto(ptr));
                                    }
                                }
                            }
                        }
                        ++MemberIndex;
                    }while (!flag1);
                }
                if (num != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(num);
                }
                if (DeviceInfoSet != IntPtr.Zero)
                {
                    try
                    {
                        DeviceManagement.SetupDiDestroyDeviceInfoList(DeviceInfoSet);
                        eReturn2 = eReturn.SUCCESS;
                    }
                    catch
                    {
                        eReturn2 = eReturn.FAILURE;
                    }
                }
                if (flag1)
                {
                    eReturn2 = eReturn.SUCCESS;
                }
            }
            return(eReturn2);
        }