-
|
PInvoke.LoadLibraryEx returns a FreeLibrarySafeHandle: PInvoke.FreeLibrary() requires a HINSTANCE parameter: How can I get a winmdroot.Foundation.HINSTANCE from a FreeLibrarySafeHandle? also; The 2nd parameter to LoadLibraryEx should be null, according to the documentation. But null throws an exception: Using VS2022, v17.4.3, .Net 7.0, Windows Target OS 10.0.20348 Console App. and Microsoft.Windows.CsWin32 0.2.164-beta See Program.cs |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The null-throwing issue you found is a bug in the metadata, which I've reported for you in microsoft/win32metadata#1421. |
Beta Was this translation helpful? Give feedback.
LoadLibraryExis emitted twice: once with aSafeHandlereturn type and once withHINSTANCEas its return type. It is only necessary to callFreeLibrarywhen you use theHINSTANCEreturning overload. When you use theSafeHandleoverload, you should just dispose of theSafeHandlewhen you're done with it, and it will callFreeLibraryon your behalf.The null-throwing issue you found is a bug in the metadata, which I've reported for you in microsoft/win32metadata#1421.