-
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.
LoadLibraryEx
is emitted twice: once with aSafeHandle
return type and once withHINSTANCE
as its return type. It is only necessary to callFreeLibrary
when you use theHINSTANCE
returning overload. When you use theSafeHandle
overload, you should just dispose of theSafeHandle
when you're done with it, and it will callFreeLibrary
on your behalf.The null-throwing issue you found is a bug in the metadata, which I've reported for you in microsoft/win32metadata#1421.