Exemplo n.º 1
0
 internal static extern ConfigManagerResult CM_Get_DevNode_Property(
     uint devInst,
     ref DevPropKey propertyKey,
     out DevPropType propertyType,
     IntPtr buffer,
     ref uint bufferSize,
     uint flags);
Exemplo n.º 2
0
 internal static extern ConfigManagerResult CM_Get_Class_Property(
     Guid classGUID,
     ref DevPropKey propertyKey,
     out DevPropType propertyType,
     IntPtr buffer,
     ref uint bufferSize,
     uint flags);
Exemplo n.º 3
0
        internal static readonly DevPropKey DEVPKEY_Device_SafeRemovalRequiredOverride = new DevPropKey(0xafd97640, 0x86a3, 0x4210, 0xb6, 0x7c, 0x28, 0x9c, 0x41, 0xaa, 0xbe, 0x55, 3);  // DEVPROP_TYPE_BOOLEAN

        internal static T ConvertPropToType <T>(IntPtr propertyBufferPtr, DevPropType propertyType)
        {
            if (propertyType == DevPropType.String && typeof(T) == typeof(string))
            {
                return((T)(object)Marshal.PtrToStringUni(propertyBufferPtr));
            }
            else if (propertyType == DevPropType.FileTime && typeof(T) == typeof(DateTime))
            {
                var   time     = (System.Runtime.InteropServices.ComTypes.FILETIME)Marshal.PtrToStructure(propertyBufferPtr, typeof(System.Runtime.InteropServices.ComTypes.FILETIME));
                ulong high     = (ulong)time.dwHighDateTime;
                uint  low      = (uint)time.dwLowDateTime;
                long  fileTime = (long)((high << 32) + low);
                return((T)(object)DateTime.FromFileTimeUtc(fileTime));
            }
            else if (propertyType == DevPropType.Uint64 && typeof(T) == typeof(ulong))
            {
                return((T)(object)(ulong)Marshal.ReadInt64(propertyBufferPtr));
            }
            else if (propertyType == DevPropType.Uint32 && typeof(T) == typeof(uint))
            {
                return((T)(object)(uint)Marshal.ReadInt32(propertyBufferPtr));
            }
            else if (propertyType == DevPropType.Guid && typeof(T) == typeof(Guid))
            {
                return((T)Marshal.PtrToStructure(propertyBufferPtr, typeof(Guid)));
            }
            else if (propertyType == DevPropType.Boolean && (typeof(T) == typeof(bool) || typeof(T) == typeof(bool?)))
            {
                return((T)(object)(Marshal.ReadByte(propertyBufferPtr) != 0));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 4
0
 internal static extern ConfigManagerResult CM_Get_Device_Interface_Property(
     string pszDeviceInterface,
     ref DevPropKey PropertyKey,
     out DevPropType PropertyType,
     IntPtr PropertyBuffer,
     ref uint PropertyBufferSize,
     uint ulFlags // reserved
     );
Exemplo n.º 5
0
 internal static extern ConfigManagerResult CM_Set_DevNode_Property(
     uint devInst,
     ref DevPropKey PropertyKey,
     DevPropType PropertyType,
     IntPtr PropertyBuffer,
     uint PropertyBufferSize,
     uint ulFlags // reserved
     );
Exemplo n.º 6
0
 internal static extern bool DriverStoreSetObjectProperty(
     IntPtr driverStoreHandle,
     DriverStoreObjectType objectType,
     string objectName,
     ref DevPropKey propertyKey,
     DevPropType propertyType,
     ref uint propertyBuffer,
     int propertySize,
     DriverStoreSetObjectPropertyFlags flag);
Exemplo n.º 7
0
        internal static readonly DevPropKey DEVPKEY_DriverPackage_Invalidated           = new DevPropKey(0x8163eb01, 0x142c, 0x4f7a, 0x94, 0xe1, 0xa2, 0x74, 0xcc, 0x47, 0xdb, 0xba, 41);     // DEVPROP_TYPE_BOOLEAN

        internal static T ConvertPropToType <T>(IntPtr propertyBufferPtr, DevPropType propertyType)
        {
            if ((propertyType == DevPropType.String || propertyType == DevPropType.StringIndirect) && typeof(T) == typeof(string))
            {
                return((T)(object)Marshal.PtrToStringUni(propertyBufferPtr));
            }
            else if (propertyType == DevPropType.FileTime && typeof(T) == typeof(DateTime))
            {
                var   time     = (System.Runtime.InteropServices.ComTypes.FILETIME)Marshal.PtrToStructure(propertyBufferPtr, typeof(System.Runtime.InteropServices.ComTypes.FILETIME));
                ulong high     = (ulong)time.dwHighDateTime;
                uint  low      = (uint)time.dwLowDateTime;
                long  fileTime = (long)((high << 32) + low);
                return((T)(object)DateTime.FromFileTimeUtc(fileTime));
            }
            else if (propertyType == DevPropType.Uint64 && typeof(T) == typeof(ulong))
            {
                return((T)(object)(ulong)Marshal.ReadInt64(propertyBufferPtr));
            }
            else if (propertyType == DevPropType.Uint64 && typeof(T) == typeof(Version))
            {
                ulong driverVersion = (ulong)Marshal.ReadInt64(propertyBufferPtr);
                return((T)(object)new Version(
                           (int)((driverVersion >> 48) & 0xFFFF),
                           (int)((driverVersion >> 32) & 0xFFFF),
                           (int)((driverVersion >> 16) & 0xFFFF),
                           (int)((driverVersion >> 0) & 0xFFFF)));
            }
            else if (propertyType == DevPropType.String && typeof(T) == typeof(Version))
            {
                return((T)(object)Version.Parse(Marshal.PtrToStringUni(propertyBufferPtr)));
            }
            else if (propertyType == DevPropType.Uint32 && typeof(T) == typeof(uint))
            {
                return((T)(object)(uint)Marshal.ReadInt32(propertyBufferPtr));
            }
            else if (propertyType == DevPropType.Guid && typeof(T) == typeof(Guid))
            {
                return((T)Marshal.PtrToStructure(propertyBufferPtr, typeof(Guid)));
            }
            else if (propertyType == DevPropType.Boolean && (typeof(T) == typeof(bool) || typeof(T) == typeof(bool?)))
            {
                return((T)(object)(Marshal.ReadByte(propertyBufferPtr) != 0));
            }
            else if (propertyType == DevPropType.StringList && typeof(T) == typeof(IList <string>))
            {
                IntPtr        curStringPos = propertyBufferPtr;
                List <string> strings      = new List <string>();

                while (true)
                {
                    string curStr = Marshal.PtrToStringUni(curStringPos);
                    if (string.IsNullOrEmpty(curStr))
                    {
                        break;
                    }

                    strings.Add(curStr);
                    curStringPos = new IntPtr(curStringPos.ToInt64() + ((curStr.Length + 1) * sizeof(char)));
                }

                return((T)(object)strings);
            }
            else
            {
                throw new NotImplementedException();
            }
        }