From f23ac13c853ef3d2c864cd7e6f934f539f9bc710 Mon Sep 17 00:00:00 2001 From: Loni Tra Date: Tue, 19 Nov 2024 14:20:34 -0800 Subject: [PATCH] Call correct HtmlHelp overload --- .../src/NativeMethods.txt | 1 + .../src/Windows/Win32/PInvoke.HtmlHelp.cs | 18 ++++++------------ .../src/System/Windows/Forms/Help/Help.cs | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/System.Windows.Forms.Primitives/src/NativeMethods.txt b/src/System.Windows.Forms.Primitives/src/NativeMethods.txt index 3947d715d06..5df70140251 100644 --- a/src/System.Windows.Forms.Primitives/src/NativeMethods.txt +++ b/src/System.Windows.Forms.Primitives/src/NativeMethods.txt @@ -259,6 +259,7 @@ HideCaret HitTestThemeBackground HT* HTML_HELP_COMMAND +HtmlHelp HTREEITEM IAccessible IAccessibleEx diff --git a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.HtmlHelp.cs b/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.HtmlHelp.cs index 9d8002e41e8..46415728261 100644 --- a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.HtmlHelp.cs +++ b/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.HtmlHelp.cs @@ -1,25 +1,19 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Runtime.InteropServices; using Windows.Win32.Data.HtmlHelp; namespace Windows.Win32; internal static partial class PInvoke { - internal static unsafe HWND HtmlHelp(HWND hwndCaller, string? pszFile, HTML_HELP_COMMAND uCommand, nuint dwData) + /// + internal static unsafe HWND HtmlHelp(T hwndCaller, string? pszFile, HTML_HELP_COMMAND uCommand, nuint dwData) + where T : IHandle { - // Copied from generated code pending resolution of https://github.com/microsoft/win32metadata/issues/1749 - - fixed (char* p = pszFile) - { - HWND __retVal = LocalExternFunction(hwndCaller, p, (uint)uCommand, dwData); - return __retVal; - } - - [DllImport(Libraries.Hhctrl, ExactSpelling = true, EntryPoint = "HtmlHelpW")] - static extern HWND LocalExternFunction(HWND hwndCaller, PCWSTR pszFile, uint uCommand, nuint dwData); + HWND result = HtmlHelp(hwndCaller.Handle, pszFile, uCommand, dwData); + GC.KeepAlive(hwndCaller.Wrapper); + return result; } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Help/Help.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Help/Help.cs index 3cd518d89d8..445bf395138 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Help/Help.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Help/Help.cs @@ -146,7 +146,7 @@ private static unsafe void ShowHTML10Help(Control? parent, string? url, HelpNavi } else if (htmlParam is int intParam) { - PInvoke.HtmlHelp(handle, pathAndFileName, htmlCommand, in intParam); + PInvoke.HtmlHelp(handle, pathAndFileName, htmlCommand, (nuint)intParam); } else if (htmlParam is HH_FTS_QUERY query) {