private Object MarshalDeviceRegistryProperty(IntPtr source, Int32 length, UInt32 type)
        {
            switch (type)
            {
            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_NONE:
                return(null);

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_SZ:
            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_EXPAND_SZ:
                return(Marshal.PtrToStringAuto(source));

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_BINARY:
                return(MarshalEx.ReadByteArray(source, length));

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_DWORD:
                //case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_DWORD_LITTLE_ENDIAN:
                return((UInt32)Marshal.ReadInt32(source));

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_DWORD_BIG_ENDIAN:
                return(Endianness.Swap((UInt32)Marshal.ReadInt32(source)));

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_LINK:
                return(Marshal.PtrToStringUni(source));

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_MULTI_SZ:
                return(MarshalEx.ReadMultiSzStringList(source, length));

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_RESOURCE_LIST:
                return(null);    // TODO

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_FULL_RESOURCE_DESCRIPTOR:
                return(null);    // TODO

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_RESOURCE_REQUIREMENTS_LIST:
                return(null);    // TODO

            case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_QWORD:
                //case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_QWORD_LITTLE_ENDIAN:
                return((UInt64)Marshal.ReadInt64(source));

            default:
                return(null);
            }
        }
        private Object MarshalDeviceProperty(IntPtr source, Int32 length, UInt32 type)
        {
            // TODO: add other types; now covers only all types that are mentioned in devpkey.h
            switch (type)
            {
            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_UINT32:
                return((UInt32)Marshal.ReadInt32(source));

            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_GUID:
                return(MarshalEx.ReadGuid(source, length));

            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_FILETIME:
                return(MarshalEx.ReadFileTime(source));

            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_BOOLEAN:
                return(Marshal.ReadByte(source) != 0);

            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_STRING:
                return(Marshal.PtrToStringUni(source));

            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_SECURITY_DESCRIPTOR:
                return(MarshalEx.ReadSecurityDescriptor(source, length));

            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_SECURITY_DESCRIPTOR_STRING:
                return(Marshal.PtrToStringUni(source));

            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_BINARY:
                return(MarshalEx.ReadByteArray(source, length));

            case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_STRING_LIST:
                return(MarshalEx.ReadMultiSzStringList(source, length));

            default:
                return(null);
            }
        }