Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Add SetupDiGetDeviceProperty to SetupApi #443

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/SetupApi/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PInvoke.SetupApi.DEVPROPKEY
PInvoke.SetupApi.DEVPROPKEY.DEVPROPKEY() -> void
PInvoke.SetupApi.DEVPROPKEY.fmtid -> System.Guid
PInvoke.SetupApi.DEVPROPKEY.pid -> uint
PInvoke.SetupApi.SetupDiGetDevicePropertyFlags
PInvoke.SetupApi.SetupDiGetDevicePropertyFlags.None = 0 -> PInvoke.SetupApi.SetupDiGetDevicePropertyFlags
static PInvoke.SetupApi.SetupDiGetDeviceProperty(PInvoke.SetupApi.SafeDeviceInfoSetHandle deviceInfoSet, PInvoke.SetupApi.SP_DEVINFO_DATA* deviceInfoData, PInvoke.SetupApi.DEVPROPKEY* propertyKey, uint* propertyType, byte[] propertyBuffer, uint propertyBufferSize, uint* requiredSize, PInvoke.SetupApi.SetupDiGetDevicePropertyFlags flags) -> bool
static PInvoke.SetupApi.SetupDiGetDeviceProperty(PInvoke.SetupApi.SafeDeviceInfoSetHandle deviceInfoSet, System.IntPtr deviceInfoData, System.IntPtr propertyKey, System.IntPtr propertyType, System.IntPtr propertyBuffer, uint propertyBufferSize, System.IntPtr requiredSize, PInvoke.SetupApi.SetupDiGetDevicePropertyFlags flags) -> bool
static PInvoke.SetupApi.SetupDiGetDeviceProperty(PInvoke.SetupApi.SafeDeviceInfoSetHandle deviceInfoSet, System.IntPtr deviceInfoData, System.IntPtr propertyKey, System.IntPtr propertyType, byte[] propertyBuffer, uint propertyBufferSize, System.IntPtr requiredSize, PInvoke.SetupApi.SetupDiGetDevicePropertyFlags flags) -> bool
static extern PInvoke.SetupApi.SetupDiGetDeviceProperty(PInvoke.SetupApi.SafeDeviceInfoSetHandle deviceInfoSet, PInvoke.SetupApi.SP_DEVINFO_DATA* deviceInfoData, PInvoke.SetupApi.DEVPROPKEY* propertyKey, uint* propertyType, byte* propertyBuffer, uint propertyBufferSize, uint* requiredSize, PInvoke.SetupApi.SetupDiGetDevicePropertyFlags flags) -> bool
32 changes: 32 additions & 0 deletions src/SetupApi/SetupApi+DEVPROPKEY.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
using System;
using System.Collections.Generic;
using System.Text;

/// <content>
/// Contains the <see cref="DEVPROPKEY"/> nested type.
/// </content>
public partial class SetupApi
{
/// <summary>
/// In Windows Vista and later versions of Windows, the DEVPROPKEY structure represents a device property key for a device property in the
/// <see href="https://docs.microsoft.com/windows-hardware/drivers/install/unified-device-property-model--windows-vista-and-later-">unified device property model</see>.
/// </summary>
public struct DEVPROPKEY
{
/// <summary>
/// A value that specifies a property category.
/// </summary>
public Guid fmtid;

/// <summary>
/// A value that uniquely identifies the property within the property category. For internal system reasons, a property identifier must be greater than or equal to two.
/// </summary>
public uint pid;
}
}
}
25 changes: 25 additions & 0 deletions src/SetupApi/SetupApi+SetupDiGetDevicePropertyFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
using System;

/// <content>
/// Contains the <see cref="SetupDiGetDevicePropertyFlags"/> nested type.
/// </content>
public partial class SetupApi
{
/// <summary>
/// Flags for the <see cref="SetupDiGetDeviceProperty(SafeDeviceInfoSetHandle, SP_DEVINFO_DATA*, DEVPROPKEY*, uint*, byte*, uint, uint*, SetupDiGetDevicePropertyFlags)"/> method.
/// </summary>
[Flags]
public enum SetupDiGetDevicePropertyFlags
{
/// <summary>
/// No flags.
/// </summary>
None = 0,
}
}
}
39 changes: 39 additions & 0 deletions src/SetupApi/SetupApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public static partial class SetupApi
/// <see cref="Marshal.GetLastWin32Error" />.
/// </returns>
[DllImport(nameof(SetupApi), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool SetupDiEnumDeviceInterfaces(
SafeDeviceInfoSetHandle deviceInfoSet,
[Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] SP_DEVINFO_DATA* deviceInfoData,
Expand Down Expand Up @@ -149,6 +150,7 @@ public static partial class SetupApi
/// <see cref="Marshal.GetLastWin32Error" />.
/// </returns>
[DllImport(nameof(SetupApi), SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool SetupDiGetDeviceInterfaceDetail(
SafeDeviceInfoSetHandle deviceInfoSet,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
Expand Down Expand Up @@ -176,11 +178,47 @@ public static partial class SetupApi
/// <see cref="Marshal.GetLastWin32Error" />.
/// </returns>
[DllImport(nameof(SetupApi), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool SetupDiEnumDeviceInfo(
SafeDeviceInfoSetHandle deviceInfoSet,
int memberIndex,
SP_DEVINFO_DATA* deviceInfoData);

/// <summary>
/// Retrieves a device instance property.
/// </summary>
/// <param name="deviceInfoSet">A handle to a <see href="https://docs.microsoft.com/windows-hardware/drivers/install/device-information-sets">device information set</see>
/// that contains a device instance for which to retrieve a device instance property.</param>
/// <param name="deviceInfoData">A pointer to the <see cref="SP_DEVINFO_DATA"/> structure that represents the device instance for which to retrieve a device instance property.</param>
/// <param name="propertyKey">A pointer to a <see cref="DEVPROPKEY"/> structure that represents the device property key of the requested device instance property.</param>
/// <param name="propertyType">A pointer to a uint-typed variable that receives the property-data-type identifier of the requested device instance property, where the property-data-type
/// identifier is the bitwise OR between a base-data-type identifier and, if the base-data type is modified, a property-data-type modifier.</param>
/// <param name="propertyBuffer">
/// A pointer to a buffer that receives the requested device instance property.
/// <see cref="SetupDiGetDeviceProperty(SafeDeviceInfoSetHandle, SP_DEVINFO_DATA*, DEVPROPKEY*, uint*, byte*, uint, uint*, SetupDiGetDevicePropertyFlags)"/> retrieves the requested property
/// only if the buffer is large enough to hold all the property value data. The pointer can be NULL. If the pointer is set to NULL and RequiredSize is supplied,
/// <see cref="SetupDiGetDeviceProperty(SafeDeviceInfoSetHandle, SP_DEVINFO_DATA*, DEVPROPKEY*, uint*, byte*, uint, uint*, SetupDiGetDevicePropertyFlags)"/> returns the size of the property,
/// in bytes, in <paramref name="requiredSize"/>.</param>
/// <param name="propertyBufferSize">The size, in bytes, of the <paramref name="propertyBuffer"/> buffer. If <paramref name="propertyBuffer"/> is set to NULL, <paramref name="propertyBufferSize"/> must be set to zero.</param>
/// <param name="requiredSize">
/// A pointer to a DWORD-typed variable that receives the size, in bytes, of either the device instance property if the property is retrieved or the required buffer size if the buffer is not large enough. This pointer can be set to NULL.
/// </param>
/// <param name="flags">This parameter must be set to zero.</param>
/// <returns>
/// Returns TRUE if it is successful. Otherwise, it returns FALSE, and the logged error can be retrieved by calling <see cref="Marshal.GetLastWin32Error"/>.
/// </returns>
[DllImport(nameof(SetupApi), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool SetupDiGetDeviceProperty(
SafeDeviceInfoSetHandle deviceInfoSet,
SP_DEVINFO_DATA* deviceInfoData,
DEVPROPKEY* propertyKey,
uint* propertyType,
byte* propertyBuffer,
uint propertyBufferSize,
uint* requiredSize,
SetupDiGetDevicePropertyFlags flags);

/// <summary>
/// Deletes a device information set and frees all associated memory.
/// </summary>
Expand All @@ -195,6 +233,7 @@ public static partial class SetupApi
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#endif
[DllImport(nameof(SetupApi), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);
}
}