当前位置: 首页>>代码示例>>C#>>正文


C# SP_DEVINFO_DATA类代码示例

本文整理汇总了C#中SP_DEVINFO_DATA的典型用法代码示例。如果您正苦于以下问题:C# SP_DEVINFO_DATA类的具体用法?C# SP_DEVINFO_DATA怎么用?C# SP_DEVINFO_DATA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SP_DEVINFO_DATA类属于命名空间,在下文中一共展示了SP_DEVINFO_DATA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetupDiEnumDeviceInterfaces

 private static extern Boolean SetupDiEnumDeviceInterfaces(
     IntPtr hDevInfo,
     ref SP_DEVINFO_DATA devInfo,
     ref Guid interfaceClassGuid,
     UInt32 memberIndex,
     ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData
     );
开发者ID:pengxiangqi1991,项目名称:Camera-Control,代码行数:7,代码来源:SetupApi.cs

示例2: SetupDiEnumDeviceInterfacesHelper

        private static IEnumerable<SP_DEVICE_INTERFACE_DATA> SetupDiEnumDeviceInterfacesHelper(
            SafeDeviceInfoSetHandle lpDeviceInfoSet,
            SP_DEVINFO_DATA? deviceInfoData,
            Guid interfaceClassGuid)
        {
            int index = 0;
            while (true)
            {
                var data = SP_DEVICE_INTERFACE_DATA.Create();

                bool result = SetupDiEnumDeviceInterfaces(
                    lpDeviceInfoSet,
                    deviceInfoData,
                    ref interfaceClassGuid,
                    index,
                    ref data);

                if (!result)
                {
                    var lastError = GetLastError();
                    if (lastError != Win32ErrorCode.ERROR_NO_MORE_ITEMS)
                    {
                        throw new Win32Exception(lastError);
                    }

                    yield break;
                }

                yield return data;
                index++;
            }
        }
开发者ID:jmelosegui,项目名称:pinvoke,代码行数:32,代码来源:SetupApi.Helpers.cs

示例3: SetupDiOpenDevRegKey

 public static extern IntPtr SetupDiOpenDevRegKey(
     IntPtr hDeviceInfoSet,
     ref SP_DEVINFO_DATA deviceInfoData,
     int scope,
     int hwProfile,
     int parameterRegistryValueKind,
     int samDesired);
开发者ID:beaugunderson,项目名称:EdidExample,代码行数:7,代码来源:NativeMethods.cs

示例4: Main

        static void Main(string[] args)
        {
            int deviceCount = 0;
            IntPtr deviceList = IntPtr.Zero;
            // GUID for processor classid
            Guid processorGuid = new Guid("{50127dc3-0f36-415e-a6cc-4cb3be910b65}");

            try
            {
                // get a list of all processor devices
                deviceList = SetupDiGetClassDevs(ref processorGuid, "ACPI", IntPtr.Zero, (int)DIGCF.PRESENT);
                // attempt to process each item in the list
                for (int deviceNumber = 0; ; deviceNumber++)
                {
                    SP_DEVINFO_DATA deviceInfo = new SP_DEVINFO_DATA();
                    deviceInfo.cbSize = Marshal.SizeOf(deviceInfo);

                    // attempt to read the device info from the list, if this fails, we're at the end of the list
                    if (!SetupDiEnumDeviceInfo(deviceList, deviceNumber, ref deviceInfo))
                    {
                        deviceCount = deviceNumber - 1;
                        break;
                    }
                }
            }
            finally
            {
                if (deviceList != IntPtr.Zero) { SetupDiDestroyDeviceInfoList(deviceList); }
            }
            Console.WriteLine("Number of cores: {0}{1}{2}{3}", Environment.MachineName, Environment.ExitCode, Environment.CurrentDirectory,Environment.SystemDirectory);
        }
开发者ID:kubo08,项目名称:team-project,代码行数:31,代码来源:Program.cs

示例5: DeviceInfo

 public DeviceInfo(DeviceEnumerator deviceEnumerator, SP_DEVINFO_DATA devinfoData, string devicePath, string deviceID, string userFriendlyName)
 {
     this.deviceEnumerator = deviceEnumerator;
     this.devinfoData = devinfoData;
     DevicePath = devicePath;
     DeviceID = deviceID;
     UserFriendlyName = userFriendlyName;
 }
开发者ID:timofonic,项目名称:WinFLASHTool,代码行数:8,代码来源:DeviceEnumerator.cs

示例6: SetupDiGetDeviceInterfaceDetail

 static extern Boolean SetupDiGetDeviceInterfaceDetail(
    IntPtr hDevInfo,
    ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
    ref SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData,
    UInt32 deviceInterfaceDetailDataSize,
    out UInt32 requiredSize,
    ref SP_DEVINFO_DATA deviceInfoData
 );
开发者ID:jedijosh920,项目名称:KeyboardAudio,代码行数:8,代码来源:KeyboardWriter.cs

示例7: SetupDiGetDeviceRegistryPropertyA

		  SetupDiGetDeviceRegistryPropertyA(
				IntPtr DeviceInfoSet,
				SP_DEVINFO_DATA	 DeviceInfoData,
				UInt32 Property,
				UInt32   PropertyRegDataType,
				StringBuilder  PropertyBuffer,
				UInt32 PropertyBufferSize,
				IntPtr RequiredSize);
开发者ID:golf2109,项目名称:StepperControl,代码行数:8,代码来源:DevInfo.cs

示例8: SetupDiEnumDeviceInterfaces

 public static unsafe IEnumerable<SP_DEVICE_INTERFACE_DATA> SetupDiEnumDeviceInterfaces(
     SafeDeviceInfoSetHandle lpDeviceInfoSet,
     SP_DEVINFO_DATA* deviceInfoData,
     Guid interfaceClassGuid)
 {
     // Copy out the value of the struct pointed to (if any) so that
     // the caller does not need to remember to keep the pointer fixed
     // for the entire enumeration.
     var deviceInfoDataCopy = deviceInfoData != null ? (SP_DEVINFO_DATA?)*deviceInfoData : null;
     return SetupDiEnumDeviceInterfacesHelper(
         lpDeviceInfoSet,
         deviceInfoDataCopy,
         interfaceClassGuid);
 }
开发者ID:jmelosegui,项目名称:pinvoke,代码行数:14,代码来源:SetupApi.Helpers.cs

示例9: ComPortNameFromFriendlyNamePrefix

        /// <summary>
        /// Retrieves a COM Port Name from the friendly name prefix
        /// </summary>
        /// <param name="friendlyNamePrefix">Prefix to search with</param>
        /// <returns></returns>
        public static string ComPortNameFromFriendlyNamePrefix(string friendlyNamePrefix)
        {
            const string className = "Ports";
            Guid[] guids = GetClassGUIDs(className);

            System.Text.RegularExpressions.Regex friendlyNameToComPort =
                new System.Text.RegularExpressions.Regex(@".? \((COM\d+)\)$");  // "..... (COMxxx)" -> COMxxxx

            foreach (Guid guid in guids)
            {
                // We start at the "root" of the device tree and look for all
                // devices that match the interface GUID of a disk
                Guid guidClone = guid;
                IntPtr h = SetupDiGetClassDevs(ref guidClone, IntPtr.Zero, IntPtr.Zero, DIGCF_PRESENT | DIGCF_PROFILE);
                if (h.ToInt32() != INVALID_HANDLE_VALUE)
                {
                    int nDevice = 0;
                    while (true)
                    {
                        SP_DEVINFO_DATA da = new SP_DEVINFO_DATA();
                        da.cbSize = (uint)Marshal.SizeOf(da);

                        if (0 == SetupDiEnumDeviceInfo(h, nDevice++, ref da))
                            break;

                        uint RegType;
                        byte[] ptrBuf = new byte[BUFFER_SIZE];
                        uint RequiredSize;
                        if (SetupDiGetDeviceRegistryProperty(h, ref da,
                            (uint)SPDRP.FRIENDLYNAME, out RegType, ptrBuf,
                            BUFFER_SIZE, out RequiredSize))
                        {
                            const int utf16terminatorSize_bytes = 2;
                            string friendlyName = System.Text.UnicodeEncoding.Unicode.GetString(ptrBuf, 0, (int)RequiredSize - utf16terminatorSize_bytes);

                            if (!friendlyName.StartsWith(friendlyNamePrefix))
                                continue;

                            if (!friendlyNameToComPort.IsMatch(friendlyName))
                                continue;

                            return friendlyNameToComPort.Match(friendlyName).Groups[1].Value;
                        }
                    } // devices
                    SetupDiDestroyDeviceInfoList(h);
                }
            } // class guids

            return null;
        }
开发者ID:dcolli,项目名称:badgeup,代码行数:55,代码来源:SetupDeviceWrapper.cs

示例10: GetRegProp

 Boolean GetRegProp(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA devInfo, uint property, out string propertyVal)
 {
     uint RequiredSize = 0;
     uint RegType;
     propertyVal = null;
     SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref devInfo, property, out RegType, IntPtr.Zero, 0, out RequiredSize);
     if (RequiredSize > 0)
     {
         IntPtr ptrBuf = Marshal.AllocHGlobal((int)RequiredSize);
         if (SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref devInfo, property, out RegType, ptrBuf, RequiredSize, out RequiredSize))
             propertyVal = Marshal.PtrToStringAuto(ptrBuf);
         Marshal.FreeHGlobal(ptrBuf);
     }
     return propertyVal != null;
 }
开发者ID:ADVALAIN596,项目名称:busdog,代码行数:15,代码来源:DeviceManagement.cs

示例11: GetInstanceId

 Boolean GetInstanceId(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA devInfo, out string instanceId)
 {
     uint RequiredSize = 256;
     instanceId = null;
     IntPtr ptrBuf = Marshal.AllocHGlobal((int)RequiredSize);
     if (SetupDiGetDeviceInstanceId(deviceInfoSet, ref devInfo, ptrBuf, RequiredSize, out RequiredSize))
         instanceId = Marshal.PtrToStringAuto(ptrBuf);
     else if (RequiredSize > 0)
     {
         Marshal.ReAllocHGlobal(ptrBuf, new IntPtr(RequiredSize));
         if (SetupDiGetDeviceInstanceId(deviceInfoSet, ref devInfo, ptrBuf, RequiredSize, out RequiredSize))
             instanceId = Marshal.PtrToStringAuto(ptrBuf);
     }
     Marshal.FreeHGlobal(ptrBuf);
     return instanceId != null;
 }
开发者ID:ADVALAIN596,项目名称:busdog,代码行数:16,代码来源:DeviceManagement.cs

示例12: SetupDiGetDeviceInterfaceDetail

        public static unsafe string SetupDiGetDeviceInterfaceDetail(
            SafeDeviceInfoSetHandle deviceInfoSet,
            SP_DEVICE_INTERFACE_DATA interfaceData,
            SP_DEVINFO_DATA* deviceInfoData)
        {
            int requiredSize;

            // First call to get the size to allocate
            SetupDiGetDeviceInterfaceDetail(
                deviceInfoSet,
                ref interfaceData,
                null,
                0,
                &requiredSize,
                deviceInfoData);

            // As we passed an empty buffer we know that the function will fail, not need to check the result.
            var lastError = GetLastError();
            if (lastError != Win32ErrorCode.ERROR_INSUFFICIENT_BUFFER)
            {
                throw new Win32Exception(lastError);
            }

            fixed (byte* pBuffer = new byte[requiredSize])
            {
                var pDetail = (SP_DEVICE_INTERFACE_DETAIL_DATA*)pBuffer;
                pDetail->cbSize = SP_DEVICE_INTERFACE_DETAIL_DATA.ReportableStructSize;

                // Second call to get the value
                var success = SetupDiGetDeviceInterfaceDetail(
                    deviceInfoSet,
                    ref interfaceData,
                    pDetail,
                    requiredSize,
                    null,
                    null);

                if (!success)
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    return null;
                }

                return SP_DEVICE_INTERFACE_DETAIL_DATA.GetDevicePath(pDetail);
            }
        }
开发者ID:jmelosegui,项目名称:pinvoke,代码行数:46,代码来源:SetupApi.Helpers.cs

示例13: Create

        public static bool Create(string className, Guid classGuid, string node)
        {
            var deviceInfoSet = (IntPtr)(-1);
            var deviceInfoData = new SP_DEVINFO_DATA();

            try
            {
                deviceInfoSet = SetupDiCreateDeviceInfoList(ref classGuid, IntPtr.Zero);

                if (deviceInfoSet == (IntPtr)(-1))
                {
                    return false;
                }

                deviceInfoData.cbSize = Marshal.SizeOf(deviceInfoData);

                if (
                    !SetupDiCreateDeviceInfo(deviceInfoSet, className, ref classGuid, null, IntPtr.Zero,
                        DICD_GENERATE_ID, ref deviceInfoData))
                {
                    return false;
                }

                if (
                    !SetupDiSetDeviceRegistryProperty(deviceInfoSet, ref deviceInfoData, SPDRP_HARDWAREID, node,
                        node.Length * 2))
                {
                    return false;
                }

                if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, deviceInfoSet, ref deviceInfoData))
                {
                    return false;
                }
            }
            finally
            {
                if (deviceInfoSet != (IntPtr)(-1))
                {
                    SetupDiDestroyDeviceInfoList(deviceInfoSet);
                }
            }

            return true;
        }
开发者ID:theczorn,项目名称:ScpToolkit,代码行数:45,代码来源:Devcon.cs

示例14: Guid

        public static Guid GuidDevinterfaceUSBDevice = new Guid(GUID_DEVINTERFACE_USB_DEVICE); // USB devices
        #endregion

        /// <summary>
        /// ISBデバイスのDescriptionの一覧を作成する
        /// </summary>
        public static IList<string> MakeDeviceList()
        {
            List<string> list = new List<string>();

            Guid guid = Guid.Empty;
            IntPtr DevInfoHandle = IntPtr.Zero;

            //DevInfoHandle = SetupDiGetClassDevs(
            //                         IntPtr.Zero, null, IntPtr.Zero,
            //                         DIGCF_ALLCLASSES | DIGCF_PRESENT);

            // USBデバイスだけ列挙
            DevInfoHandle = SetupDiGetClassDevs(
                            ref GuidDevinterfaceUSBDevice, IntPtr.Zero, IntPtr.Zero,
                            DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);

            SP_DEVINFO_DATA DevInfoData = new SP_DEVINFO_DATA
            {
                classGuid = Guid.Empty,
                devInst = 0,
                reserved = IntPtr.Zero
            };

            DevInfoData.cbSize = (uint)Marshal.SizeOf(DevInfoData);// 32, // 28 When 32-Bit, 32 When 64-Bit,

            for (uint i = 0; SetupDiEnumDeviceInfo(DevInfoHandle, i, ref DevInfoData); i++)
            {
                string str = GetStringPropertyForDevice(
                    DevInfoHandle,
                    DevInfoData,
                    (uint)SetupDiGetDeviceRegistryPropertyEnum.SPDRP_DEVICEDESC);

                if (str != null)
                    list.Add(str.Replace("\0", ""));
                else
                    str = "(null)";

                // I-O DATA GV-USB2t.gvusb2.name%;I-O DATA GV-USB2
                Debug.WriteLine(str.Replace("\0", ""));
            }
            SetupDiDestroyDeviceInfoList(DevInfoHandle);

            return list;
        }
开发者ID:ikageso,项目名称:USBCheck,代码行数:50,代码来源:Win32Helper.cs

示例15: GetDevicePath

        public string GetDevicePath(Guid classGuid)
        {
            IntPtr hDevInfo = IntPtr.Zero;
            try
            {
                hDevInfo = SetupDiGetClassDevs(ref classGuid, null, IntPtr.Zero, DiGetClassFlags.DIGCF_DEVICEINTERFACE | DiGetClassFlags.DIGCF_PRESENT);

                if (hDevInfo.ToInt64() <= 0)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                SP_DEVICE_INTERFACE_DATA dia = new SP_DEVICE_INTERFACE_DATA();
                dia.cbSize = (uint)Marshal.SizeOf(dia);

                SP_DEVINFO_DATA devInfo = new SP_DEVINFO_DATA();
                devInfo.cbSize = (UInt32)Marshal.SizeOf(devInfo);

                UInt32 i = 0;

                // start the enumeration
                if (!SetupDiEnumDeviceInterfaces(hDevInfo, null, ref classGuid, i, dia))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SP_DEVICE_INTERFACE_DETAIL_DATA();
                didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)

                UInt32 requiredSize = 0;

                if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, dia, ref didd, 256, out requiredSize, devInfo))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                return didd.DevicePath;

            }
            finally
            {
                SetupDiDestroyDeviceInfoList(hDevInfo);
            }
        }
开发者ID:bwillard,项目名称:home-integration-platform,代码行数:44,代码来源:DeviceFinder.cs


注:本文中的SP_DEVINFO_DATA类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。