From 768eb8f21cbe905f8c4a0de267e9b5e7bd8d5e28 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Thu, 21 Jan 2021 20:49:25 -0700 Subject: [PATCH] Fix `GetModuleHandle` so its use doesn't prematurely unload a module Fixes #563 --- src/Kernel32/PublicAPI.Shipped.txt | 2 +- src/Kernel32/storebanned/Kernel32.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kernel32/PublicAPI.Shipped.txt b/src/Kernel32/PublicAPI.Shipped.txt index cd50bcdb..4cc693fa 100644 --- a/src/Kernel32/PublicAPI.Shipped.txt +++ b/src/Kernel32/PublicAPI.Shipped.txt @@ -1320,7 +1320,7 @@ static extern PInvoke.Kernel32.GetDllDirectory(int nBufferLength, char* lpBuffer static extern PInvoke.Kernel32.GetExitCodeProcess(System.IntPtr hProcess, out int lpExitCode) -> bool static extern PInvoke.Kernel32.GetExitCodeThread(System.IntPtr hThread, out int lpExitCode) -> bool static extern PInvoke.Kernel32.GetLargestConsoleWindowSize(System.IntPtr hConsoleOutput) -> PInvoke.COORD -static extern PInvoke.Kernel32.GetModuleHandle(string lpModuleName) -> PInvoke.Kernel32.SafeLibraryHandle +static extern PInvoke.Kernel32.GetModuleHandle(string lpModuleName) -> System.IntPtr static extern PInvoke.Kernel32.GetModuleHandleEx(PInvoke.Kernel32.GetModuleHandleExFlags dwFlags, string lpModuleName, out PInvoke.Kernel32.SafeLibraryHandle phModule) -> bool static extern PInvoke.Kernel32.GetNamedPipeClientComputerName(PInvoke.Kernel32.SafeObjectHandle Pipe, System.Text.StringBuilder ClientComputerName, int ClientComputerNameLength) -> bool static extern PInvoke.Kernel32.GetNamedPipeClientComputerName(PInvoke.Kernel32.SafeObjectHandle Pipe, char* ClientComputerName, int ClientComputerNameLength) -> bool diff --git a/src/Kernel32/storebanned/Kernel32.cs b/src/Kernel32/storebanned/Kernel32.cs index ac34c31a..cec55534 100644 --- a/src/Kernel32/storebanned/Kernel32.cs +++ b/src/Kernel32/storebanned/Kernel32.cs @@ -1352,7 +1352,7 @@ public static unsafe extern bool GetDllDirectory( /// Therefore, do not pass a handle returned by this function to the function. Doing so can cause a DLL module to be unmapped prematurely. /// [DllImport(nameof(Kernel32), SetLastError = true, CharSet = CharSet.Unicode)] - public static extern SafeLibraryHandle GetModuleHandle(string lpModuleName); + public static extern IntPtr GetModuleHandle(string lpModuleName); /// /// Retrieves a module handle for the specified module and increments the module's reference count unless is specified.