I’m loading a COM dll using this method:
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
private extern static IntPtr LoadLibrary(string librayName);
Should I release the dll using:
[DllImport("kernel32", SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hModule);
or just let the application termination handle it?
You should call
FreeLibrarywhen you’re done using a DLL that you loaded usingLoadLibrary. This will not be an issue unless your application is long-running and you load many of these DLLs, or unless you would want to update the DLL on disk (it would be locked as long as it’s loaded).By the way, why are you using
LoadLibraryto load a COM DLL and not using TLBIMP to create a .NET-accessible wrapper?