- 
                Notifications
    You must be signed in to change notification settings 
- Fork 114
Description
Actual behavior
GetModuleHandle returns FreeLibrarySafeHandle. Which will call FreeLibrary on cleanup. But, according to the documentation, this is not necessary to avoid errors:
The
GetModuleHandlefunction returns a handle to a mapped module without incrementing its reference count. However, if this handle is passed to theFreeLibraryfunction, the reference count of the mapped module will be decremented. Therefore, do not pass a handle returned byGetModuleHandleto theFreeLibraryfunction. Doing so can cause a DLL module to be unmapped prematurely.
https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandlew#remarks
GetModuleHandleEx partly also affected by this problem, because the cleanup behavior depends on the arguments passed
https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandleexw#parameters
Expected behavior
A clear and concise description of what you expected to happen.
Repro steps
- NativeMethods.txtcontent:
GetModuleHandle
- NativeMethods.jsoncontent (if present):
- Any of your own code that should be shared?
Context
- CsWin32 version: [e.g. 0.1.635-beta]
- Win32Metadata version (if explicitly set by project):
- Target Framework: [e.g. netstandard2.0]
- LangVersion(if explicitly set by project): [e.g.- 9]