GetAsStringArray() static private method

static private GetAsStringArray ( byte buffer, int len ) : string[]
buffer byte
len int
return string[]
Esempio n. 1
0
        private static bool BuildMasterCallback(IntPtr deviceInfoSet, int deviceindex, ref SetupApi.SP_DEVINFO_DATA deviceInfoData, object userData)
        {
            MasterList    deviceList = userData as MasterList;
            MasterItem    deviceItem = new MasterItem();
            StringBuilder sb         = new StringBuilder(256);

            if (SetupApi.CM_Get_Device_ID(deviceInfoData.DevInst, sb, sb.Capacity, 0) != SetupApi.CR.SUCCESS)
            {
                return(false);
            }

            deviceItem.Add(DEVICE_ID_KEY, sb.ToString());
            deviceList.Add(deviceItem);


            RegistryValueKind propertyType;

            byte[] propBuffer = new byte[256];
            int    requiredSize;
            bool   bSuccess = SetupApi.SetupDiGetCustomDeviceProperty(deviceInfoSet,
                                                                      ref deviceInfoData,
                                                                      UsbRegistry.DEVICE_INTERFACE_GUIDS,
                                                                      SetupApi.DICUSTOMDEVPROP.NONE,
                                                                      out propertyType,
                                                                      propBuffer,
                                                                      propBuffer.Length,
                                                                      out requiredSize);

            if (bSuccess)
            {
                string[] devInterfaceGuids = UsbRegistry.GetAsStringArray(propBuffer, requiredSize);

                deviceItem.Add(UsbRegistry.DEVICE_INTERFACE_GUIDS, devInterfaceGuids);
                foreach (string s in devInterfaceGuids)
                {
                    Guid          g = new Guid(s);
                    List <string> devicePathList;
                    if (WinUsb.WinUsbRegistry.GetDevicePathList(g, out devicePathList))
                    {
                        deviceItem.DevicePaths.Add(g, devicePathList);
                    }
                }
            }
            else
            {
                bSuccess = SetupApi.SetupDiGetCustomDeviceProperty(deviceInfoSet,
                                                                   ref deviceInfoData,
                                                                   UsbRegistry.LIBUSB_INTERFACE_GUIDS,
                                                                   SetupApi.DICUSTOMDEVPROP.NONE,
                                                                   out propertyType,
                                                                   propBuffer,
                                                                   propBuffer.Length,
                                                                   out requiredSize);
                if (bSuccess)
                {
                    string[] devInterfaceGuids = UsbRegistry.GetAsStringArray(propBuffer, requiredSize);

                    deviceItem.Add(UsbRegistry.LIBUSB_INTERFACE_GUIDS, devInterfaceGuids);
                }
            }

            bSuccess =
                SetupApi.SetupDiGetCustomDeviceProperty(deviceInfoSet,
                                                        ref deviceInfoData,
                                                        UsbRegistry.SYMBOLIC_NAME_KEY,
                                                        SetupApi.DICUSTOMDEVPROP.NONE,
                                                        out propertyType,
                                                        propBuffer,
                                                        propBuffer.Length,
                                                        out requiredSize);
            if (bSuccess)
            {
                string symbolicName = UsbRegistry.GetAsString(propBuffer, requiredSize);
                deviceItem.Add(UsbRegistry.SYMBOLIC_NAME_KEY, symbolicName);
            }
            SetupApi.getSPDRPProperties(deviceInfoSet, ref deviceInfoData, deviceItem);

            return(false);
        }