コード例 #1
0
ファイル: HidDevice.cs プロジェクト: luyang14/LoRa-1
        private static string GetDevicePath(IntPtr DeviceInfoTable, ref SemtechLib.Devices.Common.NativeMethods.SP_DEVICE_INTERFACE_DATA InterfaceDataStructure)
        {
            int RequiredSize = 0;

            SemtechLib.Devices.Common.NativeMethods.SP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData = new SemtechLib.Devices.Common.NativeMethods.SP_DEVICE_INTERFACE_DETAIL_DATA();
            interfaceDetailData.cbSize = Marshal.SizeOf(interfaceDetailData);
            SemtechLib.Devices.Common.NativeMethods.SetupDiGetDeviceInterfaceDetail(DeviceInfoTable, ref InterfaceDataStructure, IntPtr.Zero, 0, ref RequiredSize, IntPtr.Zero);
            IntPtr hDevice = Marshal.AllocHGlobal(RequiredSize);

            interfaceDetailData.cbSize = IntPtr.Size != 8 ? 4 + Marshal.SystemDefaultCharSize : 8;
            Marshal.StructureToPtr(interfaceDetailData, hDevice, false);
            if (SemtechLib.Devices.Common.NativeMethods.SetupDiGetDeviceInterfaceDetail(DeviceInfoTable, ref InterfaceDataStructure, hDevice, RequiredSize, IntPtr.Zero, IntPtr.Zero))
            {
                string devicePath = Marshal.PtrToStringUni(new IntPtr(hDevice.ToInt32() + 4));
                Marshal.FreeHGlobal(hDevice);
                return(devicePath);
            }
            Marshal.FreeHGlobal(hDevice);
            return(string.Empty);
        }
コード例 #2
0
ファイル: HidDevice.cs プロジェクト: kaaLabs15/LoRa
        private static string GetDevicePath(IntPtr DeviceInfoTable, ref SemtechLib.Devices.Common.NativeMethods.SP_DEVICE_INTERFACE_DATA InterfaceDataStructure)
        {
            int RequiredSize = 0;

            SemtechLib.Devices.Common.NativeMethods.SP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData = new SemtechLib.Devices.Common.NativeMethods.SP_DEVICE_INTERFACE_DETAIL_DATA();
            interfaceDetailData.cbSize = Marshal.SizeOf(interfaceDetailData);
            SemtechLib.Devices.Common.NativeMethods.SetupDiGetDeviceInterfaceDetail(DeviceInfoTable, ref InterfaceDataStructure, IntPtr.Zero, 0, ref RequiredSize, IntPtr.Zero);
            IntPtr hDevice = Marshal.AllocHGlobal(RequiredSize);
            interfaceDetailData.cbSize = IntPtr.Size != 8 ? 4 + Marshal.SystemDefaultCharSize : 8;
            Marshal.StructureToPtr(interfaceDetailData, hDevice, false);
            if (SemtechLib.Devices.Common.NativeMethods.SetupDiGetDeviceInterfaceDetail(DeviceInfoTable, ref InterfaceDataStructure, hDevice, RequiredSize, IntPtr.Zero, IntPtr.Zero))
            {
                string devicePath = Marshal.PtrToStringUni(new IntPtr(hDevice.ToInt32() + 4));
                Marshal.FreeHGlobal(hDevice);
                return devicePath;
            }
            Marshal.FreeHGlobal(hDevice);
            return string.Empty;
        }