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

Commit 12cc760

Browse files
authored
Merge pull request #518 from dotnet/fixLoadString
Fix faulty User32 LoadString p/invoke
2 parents ae86fd0 + bbef35a commit 12cc760

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/User32/PublicAPI.Shipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,6 @@ static PInvoke.User32.GetWindowText(System.IntPtr hWnd, System.IntPtr lpString,
18181818
static PInvoke.User32.GetWindowText(System.IntPtr hWnd, char[] lpString, int nMaxCount) -> int
18191819
static PInvoke.User32.HELPINFO.Create() -> PInvoke.User32.HELPINFO
18201820
static PInvoke.User32.IsDialogMessage(System.IntPtr hDlg, System.IntPtr lpMsg) -> bool
1821-
static PInvoke.User32.LoadString(System.IntPtr hInstance, uint uID, out System.IntPtr lpBuffer, int cchBufferMax) -> int
18221821
static PInvoke.User32.LookupIconIdFromDirectory(System.IntPtr presbits, bool fIcon) -> int
18231822
static PInvoke.User32.LookupIconIdFromDirectory(byte[] presbits, bool fIcon) -> int
18241823
static PInvoke.User32.LookupIconIdFromDirectoryEx(System.IntPtr presbits, bool fIcon, int cxDesired, int cyDesired, PInvoke.User32.LookupIconIdFromDirectoryExFlags Flags) -> int
@@ -1916,7 +1915,6 @@ static extern PInvoke.User32.IsWindowVisible(System.IntPtr hWnd) -> bool
19161915
static extern PInvoke.User32.IsZoomed(System.IntPtr hWnd) -> bool
19171916
static extern PInvoke.User32.LoadIcon(System.IntPtr hInstance, System.IntPtr lpIconName) -> System.IntPtr
19181917
static extern PInvoke.User32.LoadIcon(System.IntPtr hInstance, string lpIconName) -> System.IntPtr
1919-
static extern PInvoke.User32.LoadString(System.IntPtr hInstance, uint uID, out char* lpBuffer, int cchBufferMax) -> int
19201918
static extern PInvoke.User32.LogicalToPhysicalPoint(System.IntPtr hwnd, ref PInvoke.POINT lpPoint) -> bool
19211919
static extern PInvoke.User32.LogicalToPhysicalPointForPerMonitorDPI(System.IntPtr hwnd, ref PInvoke.POINT lpPoint) -> bool
19221920
static extern PInvoke.User32.LookupIconIdFromDirectory(byte* presbits, bool fIcon) -> int

src/User32/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ static PInvoke.User32.EnumDisplaySettings(System.IntPtr lpszDeviceName, uint iMo
1111
static PInvoke.User32.EnumDisplaySettings(char[] lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODE lpDevMode) -> bool
1212
static PInvoke.User32.EnumDisplaySettingsEx(System.IntPtr lpszDeviceName, uint iModeNum, System.IntPtr lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
1313
static PInvoke.User32.EnumDisplaySettingsEx(char[] lpszDeviceName, uint iModeNum, ref PInvoke.DEVMODE lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
14+
static PInvoke.User32.LoadString(System.IntPtr hInstance, uint uID, char[] lpBuffer, int cchBufferMax) -> int
15+
static PInvoke.User32.LoadString(System.IntPtr hInstance, uint uID, System.IntPtr lpBuffer, int cchBufferMax) -> int
1416
static extern PInvoke.User32.EnumDisplayDevices(char* lpDevice, uint iDevNum, PInvoke.DISPLAY_DEVICE* lpDisplayDevice, PInvoke.User32.EnumDisplayDevicesFlags dwFlags) -> bool
1517
static extern PInvoke.User32.EnumDisplaySettings(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode) -> bool
1618
static extern PInvoke.User32.EnumDisplaySettingsEx(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
19+
static extern PInvoke.User32.LoadString(System.IntPtr hInstance, uint uID, char* lpBuffer, int cchBufferMax) -> int
1720
static extern PInvoke.User32.UnregisterClass(string lpClassName, System.IntPtr hInstance) -> bool
1821
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr

src/User32/User32.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,11 +2915,11 @@ public static extern IntPtr DefWindowProc(
29152915
/// The identifier of the string to be loaded.
29162916
/// </param>
29172917
/// <param name="lpBuffer">
2918-
/// The buffer is to receive the string. Must be of sufficient length to hold a pointer (8 bytes).
2918+
/// The buffer to receive the string (if <paramref name="cchBufferMax" /> is non-zero) or a read-only pointer to the string resource itself (if <paramref name="cchBufferMax" /> is zero). Must be of sufficient length to hold a pointer (8 bytes).
29192919
/// </param>
29202920
/// <param name="cchBufferMax">
29212921
/// The size of the buffer, in characters. The string is truncated and null-terminated if it is longer than the
2922-
/// number of characters specified. If this parameter is 0, then lpBuffer receives a read-only pointer to the
2922+
/// number of characters specified. If this parameter is 0, then <paramref name="lpBuffer" /> receives a read-only pointer to the
29232923
/// resource itself.
29242924
/// </param>
29252925
/// <returns>
@@ -2928,7 +2928,11 @@ public static extern IntPtr DefWindowProc(
29282928
/// error information, call <see cref="Kernel32.GetLastError"/>.
29292929
/// </returns>
29302930
[DllImport(nameof(User32), CharSet = CharSet.Unicode, SetLastError = true)]
2931-
public static extern unsafe int LoadString(IntPtr hInstance, uint uID, out char* lpBuffer, int cchBufferMax);
2931+
public static extern unsafe int LoadString(
2932+
IntPtr hInstance,
2933+
uint uID,
2934+
[Friendly(FriendlyFlags.Out | FriendlyFlags.Array)] char* lpBuffer,
2935+
int cchBufferMax);
29322936

29332937
/// <summary>
29342938
/// Retrieves the length, in characters, of the specified window's title bar text (if the window has a title bar).

0 commit comments

Comments
 (0)