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

Commit a2127ca

Browse files
committed
EnumDisplaySettings - react to PR review (#510)
1 parent cf8f33a commit a2127ca

File tree

6 files changed

+1318
-1303
lines changed

6 files changed

+1318
-1303
lines changed

src/User32.Tests/User32Facts+EnumDisplaySettingsFacts.cs

+15
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,19 @@ public void EnumDisplaySettings_Test()
2121
Assert.True(mode.dmPelsWidth > 0);
2222
Assert.True(mode.dmPelsHeight > 0);
2323
}
24+
25+
[Fact]
26+
public void EnumDisplaySettingsEx_Test()
27+
{
28+
// Arrange
29+
var mode = DEVMODE.Create();
30+
31+
// Act
32+
var result = EnumDisplaySettingsEx(null, ENUM_CURRENT_SETTINGS, ref mode, EnumDisplaySettingsExFlags.EDS_RAWMODE);
33+
34+
// Assert
35+
Assert.True(result);
36+
Assert.True(mode.dmPelsWidth > 0);
37+
Assert.True(mode.dmPelsHeight > 0);
38+
}
2439
}

src/User32/PublicAPI.Unshipped.txt

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ PInvoke.User32.EnumDisplaySettingsExFlags.EDS_RAWMODE = 2 -> PInvoke.User32.Enum
55
PInvoke.User32.EnumDisplaySettingsExFlags.EDS_ROTATEDMODE = 4 -> PInvoke.User32.EnumDisplaySettingsExFlags
66
const PInvoke.User32.ENUM_CURRENT_SETTINGS = 4294967295 -> uint
77
const PInvoke.User32.ENUM_REGISTRY_SETTINGS = 4294967294 -> uint
8-
static PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, System.IntPtr lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
9-
static PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, ref PInvoke.DISPLAY_DEVICE lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
10-
static PInvoke.User32.EnumDisplaySettings(string lpszDeviceName, uint iModeNum, System.IntPtr lpDevMode) -> bool
11-
static PInvoke.User32.EnumDisplaySettings(string lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODE lpDevMode) -> bool
12-
static PInvoke.User32.EnumDisplaySettingsEx(string lpszDeviceName, uint iModeNum, System.IntPtr lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
13-
static PInvoke.User32.EnumDisplaySettingsEx(string lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODE lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
14-
static extern PInvoke.User32.EnumDisplayDevices(string lpDevice, uint iDevNum, PInvoke.DISPLAY_DEVICE* lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
15-
static extern PInvoke.User32.EnumDisplaySettings(string lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode) -> bool
16-
static extern PInvoke.User32.EnumDisplaySettingsEx(string lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
8+
static PInvoke.User32.EnumDisplayDevices(System.IntPtr lpDevice, uint iDevNum, System.IntPtr lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
9+
static PInvoke.User32.EnumDisplayDevices(char[] lpDevice, uint iDevNum, ref PInvoke.DISPLAY_DEVICE lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
10+
static PInvoke.User32.EnumDisplaySettings(System.IntPtr lpszDeviceName, uint iModeNum, System.IntPtr lpDevMode) -> bool
11+
static PInvoke.User32.EnumDisplaySettings(char[] lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODE lpDevMode) -> bool
12+
static PInvoke.User32.EnumDisplaySettingsEx(System.IntPtr lpszDeviceName, uint iModeNum, System.IntPtr lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
13+
static PInvoke.User32.EnumDisplaySettingsEx(char[] lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODE lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
14+
static extern PInvoke.User32.EnumDisplayDevices(char* lpDevice, uint iDevNum, PInvoke.DISPLAY_DEVICE* lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
15+
static extern PInvoke.User32.EnumDisplaySettings(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode) -> bool
16+
static extern PInvoke.User32.EnumDisplaySettingsEx(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
1717
static extern PInvoke.User32.UnregisterClass(string lpClassName, System.IntPtr hInstance) -> bool
1818
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr

src/User32/User32+EnumDisplaySettingsExFlags.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace PInvoke
1111
public partial class User32
1212
{
1313
/// <summary>
14-
/// Flags for <see cref="EnumDisplaySettingsEx(string, uint, ref DEVMODE, EnumDisplaySettingsExFlags)"/>.
14+
/// Flags for <see cref="EnumDisplaySettingsEx(char*, uint, DEVMODE*, EnumDisplaySettingsExFlags)"/>.
1515
/// </summary>
1616
[Flags]
1717
public enum EnumDisplaySettingsExFlags : uint

src/User32/User32.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ public static extern unsafe int LookupIconIdFromDirectoryEx(
16771677
/// </param>
16781678
/// <param name="lpDisplayDevice">
16791679
/// A pointer to a <see cref="DISPLAY_DEVICE"/> structure that receives information about the display device specified by <paramref name="iDevNum"/>.
1680-
/// Before calling <see cref="EnumDisplayDevices(string, uint, DISPLAY_DEVICE*, EnumDisplayDevicesFlags)"/>, you must initialize the member <see cref="DISPLAY_DEVICE.cb"/> to the size, in bytes, of <see cref="DISPLAY_DEVICE"/>.
1680+
/// Before calling <see cref="EnumDisplayDevices(char*, uint, DISPLAY_DEVICE*, EnumDisplayDevicesFlags)"/>, you must initialize the member <see cref="DISPLAY_DEVICE.cb"/> to the size, in bytes, of <see cref="DISPLAY_DEVICE"/>.
16811681
/// </param>
16821682
/// <param name="dwFlags">
16831683
/// Set this flag to <see cref="EnumDisplayDevicesFlags.EDD_GET_DEVICE_INTERFACE_NAME"/> to retrieve the device interface name for <c>GUID_DEVINTERFACE_MONITOR</c>, which is registered by the operating system on a per monitor basis.
@@ -1695,7 +1695,7 @@ public static extern unsafe int LookupIconIdFromDirectoryEx(
16951695
[DllImport(nameof(User32), SetLastError = true, CharSet = CharSet.Unicode)]
16961696
[return: MarshalAs(UnmanagedType.Bool)]
16971697
public static extern unsafe bool EnumDisplayDevices(
1698-
[MarshalAs(UnmanagedType.LPWStr)] string lpDevice,
1698+
[Friendly(FriendlyFlags.Array | FriendlyFlags.In)] char* lpDevice,
16991699
uint iDevNum,
17001700
[Friendly(FriendlyFlags.Bidirectional)] DISPLAY_DEVICE* lpDisplayDevice,
17011701
EnumDisplayDevicesFlags dwFlags);
@@ -1705,21 +1705,21 @@ public static extern unsafe bool EnumDisplayDevices(
17051705
/// </summary>
17061706
/// <param name="lpszDeviceName">
17071707
/// A pointer to a null-terminated string that specifies the display device about whose graphics mode the function will obtain information.
1708-
/// This parameter is either <c>NULL</c> or a <see cref="DISPLAY_DEVICE.DeviceName"/> returned from <see cref="EnumDisplayDevices(string, uint, DISPLAY_DEVICE*, EnumDisplayDevicesFlags)"/>.
1708+
/// This parameter is either <c>NULL</c> or a <see cref="DISPLAY_DEVICE.DeviceName"/> returned from <see cref="EnumDisplayDevices(char*, uint, DISPLAY_DEVICE*, EnumDisplayDevicesFlags)"/>.
17091709
/// A <c>NULL</c> value specifies the current display device on the computer on which the calling thread is running.
17101710
/// </param>
17111711
/// <param name="iModeNum">
17121712
/// <para>The type of information to be retrieved. This value can be a graphics mode index or one of the following values.</para>
17131713
/// <para><see cref="ENUM_CURRENT_SETTINGS"/>: Retrieve the current settings for the display device.</para>
17141714
/// <para><see cref="ENUM_REGISTRY_SETTINGS"/>: Retrieve the settings for the display device that are currently stored in the registry.</para>
17151715
/// <para>
1716-
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls to <see cref="EnumDisplaySettings(string, uint, DEVMODE*)"/>, as follows: Set <paramref name="iModeNum"/> to zero for the first call,
1716+
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls to <see cref="EnumDisplaySettings(char*, uint, DEVMODE*)"/>, as follows: Set <paramref name="iModeNum"/> to zero for the first call,
17171717
/// and increment <paramref name="iModeNum"/> by one for each subsequent call.
17181718
/// </para>
17191719
/// <para>
17201720
/// Continue calling the function until the return value is zero.<br/>
1721-
/// When you call <see cref="EnumDisplaySettings(string, uint, DEVMODE*)"/> with <paramref name="iModeNum"/> set to zero, the operating system initializes and caches information about the display device.<br/>
1722-
/// When you call <see cref="EnumDisplaySettings(string, uint, DEVMODE*)"/> with <paramref name="iModeNum"/> set to a nonzero value,
1721+
/// When you call <see cref="EnumDisplaySettings(char*, uint, DEVMODE*)"/> with <paramref name="iModeNum"/> set to zero, the operating system initializes and caches information about the display device.<br/>
1722+
/// When you call <see cref="EnumDisplaySettings(char*, uint, DEVMODE*)"/> with <paramref name="iModeNum"/> set to a nonzero value,
17231723
/// the function returns the information that was cached the last time the function was called with iModeNum set to zero.
17241724
/// </para>
17251725
/// </param>
@@ -1734,7 +1734,7 @@ public static extern unsafe bool EnumDisplayDevices(
17341734
[DllImport(nameof(User32))]
17351735
[return: MarshalAs(UnmanagedType.Bool)]
17361736
public static extern unsafe bool EnumDisplaySettings(
1737-
[MarshalAs(UnmanagedType.LPWStr)] string lpszDeviceName,
1737+
[Friendly(FriendlyFlags.Array | FriendlyFlags.In)] char* lpszDeviceName,
17381738
uint iModeNum,
17391739
[Friendly(FriendlyFlags.Bidirectional)]DEVMODE* lpDevMode);
17401740

@@ -1743,21 +1743,21 @@ public static extern unsafe bool EnumDisplaySettings(
17431743
/// </summary>
17441744
/// <param name="lpszDeviceName">
17451745
/// A pointer to a null-terminated string that specifies the display device about whose graphics mode the function will obtain information.
1746-
/// This parameter is either <c>NULL</c> or a <see cref="DISPLAY_DEVICE.DeviceName"/> returned from <see cref="EnumDisplayDevices(string, uint, DISPLAY_DEVICE*, EnumDisplayDevicesFlags)"/>.
1746+
/// This parameter is either <c>NULL</c> or a <see cref="DISPLAY_DEVICE.DeviceName"/> returned from <see cref="EnumDisplayDevices(char*, uint, DISPLAY_DEVICE*, EnumDisplayDevicesFlags)"/>.
17471747
/// A <c>NULL</c> value specifies the current display device on the computer on which the calling thread is running.
17481748
/// </param>
17491749
/// <param name="iModeNum">
17501750
/// <para>The type of information to be retrieved. This value can be a graphics mode index or one of the following values.</para>
17511751
/// <para><see cref="ENUM_CURRENT_SETTINGS"/>: Retrieve the current settings for the display device.</para>
17521752
/// <para><see cref="ENUM_REGISTRY_SETTINGS"/>: Retrieve the settings for the display device that are currently stored in the registry.</para>
17531753
/// <para>
1754-
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls to <see cref="EnumDisplaySettingsEx(string, uint, DEVMODE*, EnumDisplaySettingsExFlags)"/>, as follows: Set <paramref name="iModeNum"/> to zero for the first call,
1754+
/// Graphics mode indexes start at zero. To obtain information for all of a display device's graphics modes, make a series of calls to <see cref="EnumDisplaySettingsEx(char*, uint, DEVMODE*, EnumDisplaySettingsExFlags)"/>, as follows: Set <paramref name="iModeNum"/> to zero for the first call,
17551755
/// and increment <paramref name="iModeNum"/> by one for each subsequent call.
17561756
/// </para>
17571757
/// <para>
17581758
/// Continue calling the function until the return value is zero.<br/>
1759-
/// When you call <see cref="EnumDisplaySettingsEx(string, uint, DEVMODE*, EnumDisplaySettingsExFlags)"/> with <paramref name="iModeNum"/> set to zero, the operating system initializes and caches information about the display device.<br/>
1760-
/// When you call <see cref="EnumDisplaySettingsEx(string, uint, DEVMODE*, EnumDisplaySettingsExFlags)"/> with <paramref name="iModeNum"/> set to a nonzero value,
1759+
/// When you call <see cref="EnumDisplaySettingsEx(char*, uint, DEVMODE*, EnumDisplaySettingsExFlags)"/> with <paramref name="iModeNum"/> set to zero, the operating system initializes and caches information about the display device.<br/>
1760+
/// When you call <see cref="EnumDisplaySettingsEx(char*, uint, DEVMODE*, EnumDisplaySettingsExFlags)"/> with <paramref name="iModeNum"/> set to a nonzero value,
17611761
/// the function returns the information that was cached the last time the function was called with iModeNum set to zero.
17621762
/// </para>
17631763
/// </param>
@@ -1772,10 +1772,10 @@ public static extern unsafe bool EnumDisplaySettings(
17721772
/// As noted in the description of the <paramref name="iModeNum"/> parameter, you can use this behavior to enumerate all of a display device's graphics modes.
17731773
/// </remarks>
17741774
/// <returns>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.</returns>
1775-
[DllImport(nameof(User32), EntryPoint = "EnumDisplaySettingsExW")]
1775+
[DllImport(nameof(User32))]
17761776
[return: MarshalAs(UnmanagedType.Bool)]
17771777
public static extern unsafe bool EnumDisplaySettingsEx(
1778-
[MarshalAs(UnmanagedType.LPWStr)] string lpszDeviceName,
1778+
[Friendly(FriendlyFlags.Array | FriendlyFlags.In)] char* lpszDeviceName,
17791779
uint iModeNum,
17801780
[Friendly(FriendlyFlags.Bidirectional)] DEVMODE* lpDevMode,
17811781
EnumDisplaySettingsExFlags dwFlags);

0 commit comments

Comments
 (0)