示例#1
0
文件: UsbApi.cs 项目: radtek/dev2virt
        // initializes a GUID from a 873FDF-61A8-11D1-AA5E-00C04FB1728B
        private static UsbNativeType.GUID ParseClassGuid(string classGuid)
        {
            UsbNativeType.GUID guid = new UsbNativeType.GUID();

            if ((classGuid == null) && (classGuid == string.Empty))
            {
                return(guid);
            }

            string[] data = classGuid.Split('-');
            if (data.Length != 5)
            {
                return(guid);
            }

            guid.Data1 = Int32.Parse(data[0], System.Globalization.NumberStyles.AllowHexSpecifier);
            guid.Data2 = UInt16.Parse(data[1], System.Globalization.NumberStyles.AllowHexSpecifier);
            guid.Data3 = UInt16.Parse(data[2], System.Globalization.NumberStyles.AllowHexSpecifier);
            guid.data4 = new byte[8];
            byte[] dataAux = BitConverter.GetBytes(UInt16.Parse(data[3], System.Globalization.NumberStyles.AllowHexSpecifier));
            guid.data4[0] = dataAux[1]; guid.data4[1] = dataAux[0];
            dataAux       = BitConverter.GetBytes(Int64.Parse(data[4], System.Globalization.NumberStyles.AllowHexSpecifier));
            guid.data4[2] = dataAux[5]; guid.data4[3] = dataAux[4];
            guid.data4[4] = dataAux[3]; guid.data4[5] = dataAux[2];
            guid.data4[6] = dataAux[1]; guid.data4[7] = dataAux[0];

            return(guid);
        }
示例#2
0
文件: UsbApi.cs 项目: radtek/dev2virt
        public unsafe static List <string> GetDevices(string identification, string classGuid)
        {
            string devicePath      = string.Empty;
            int    deviceNumber    = 0;
            int    hardwareDevInfo = 0;

            UsbNativeType.GUID guid;
            List <string>      devices = new List <string>();

            if (classGuid != null)
            {
                guid = ParseClassGuid(classGuid);
            }
            else
            {
                // falback to human interface devices GUID class
                guid = new UsbNativeType.GUID();
                UsbNativeApi.HidD_GetHidGuid(ref guid);
            }


            hardwareDevInfo = UsbNativeApi.SetupDiGetClassDevs(
                ref guid,
                null,
                null,
                UsbNativeApi.DIGCF_INTERFACEDEVICE | UsbNativeApi.DIGCF_PRESENT);

            // iterate through the available GUID interface devices
            while (true)
            {
                devicePath = GetDevicePath(guid, hardwareDevInfo, deviceNumber);
                if ((devicePath == null) || devicePath.Equals(String.Empty))
                {
                    UsbNativeApi.SetupDiDestroyDeviceInfoList(hardwareDevInfo);
                    return(devices);
                }
                // get 2Virt devices interfaces only
                if ((identification == null) || (devicePath.ToUpper().IndexOf(identification) > 0))
                {
                    devices.Add(devicePath);
                }
                deviceNumber++;
            }
        }
示例#3
0
文件: UsbApi.cs 项目: radtek/dev2virt
        private unsafe static string GetDevicePath(UsbNativeType.GUID guid, int hardwareDevInfo, int device_number)
        {
            int result = 0;

            UsbNativeType.SP_DEVICE_INTERFACE_DATA interfaceData = new UsbNativeType.SP_DEVICE_INTERFACE_DATA();
            interfaceData.cbSize = Marshal.SizeOf(interfaceData);

            // get the device_number device interface
            result = UsbNativeApi.SetupDiEnumDeviceInterfaces(
                hardwareDevInfo,
                0,
                ref guid,
                device_number,
                ref interfaceData);

            // get the required size for the device interface system path
            int devicePathSize = 0;

            result = UsbNativeApi.SetupDiGetDeviceInterfaceDetail(
                hardwareDevInfo,    // IN HDEVINFO  DeviceInfoSet,
                ref interfaceData,  // IN PSP_DEVICE_INTERFACE_DATA  DeviceInterfaceData,
                null,               // DeviceInterfaceDetailData,  OPTIONAL
                0,                  // IN DWORD  DeviceInterfaceDetailDataSize,
                ref devicePathSize, // OUT PDWORD  RequiredSize,  OPTIONAL
                null);              //

            // get the actual device interface details
            UsbNativeType.PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetail = new UsbNativeType.PSP_DEVICE_INTERFACE_DETAIL_DATA();
            interfaceDetail.cbSize = 5; // sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA) == 5 in C
            result = UsbNativeApi.SetupDiGetDeviceInterfaceDetail(
                hardwareDevInfo,        // IN HDEVINFO  DeviceInfoSet,
                ref interfaceData,      // IN PSP_DEVICE_INTERFACE_DATA  DeviceInterfaceData,
                ref interfaceDetail,    // DeviceInterfaceDetailData,  OPTIONAL
                devicePathSize,         // IN DWORD  DeviceInterfaceDetailDataSize,
                ref devicePathSize,     // OUT PDWORD  RequiredSize,  OPTIONAL
                null);                  //

            return(interfaceDetail.DevicePath);
        }
示例#4
0
文件: UsbApi.cs 项目: radtek/dev2virt
 public static extern unsafe int SetupDiEnumDeviceInterfaces(
     int DeviceInfoSet,
     int DeviceInfoData,
     ref UsbNativeType.GUID lpHidGuid,
     int MemberIndex,
     ref UsbNativeType.SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData);
示例#5
0
文件: UsbApi.cs 项目: radtek/dev2virt
 public static extern unsafe int SetupDiGetClassDevs(
     ref UsbNativeType.GUID lpHidGuid,
     int *Enumerator,
     int *hwndParent,
     int Flags);
示例#6
0
文件: UsbApi.cs 项目: radtek/dev2virt
 public static extern unsafe void HidD_GetHidGuid(
     ref UsbNativeType.GUID lpHidGuid);