开发者

Should I free a loaded module when disposing the object?

开发者 https://www.devze.com 2023-02-07 06:42 出处:网络
I\'m loading a COM dll using this method: [DllImport(\"kernel32\", CharSet = CharSet.Unicode, SetLastError = true)]

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 d开发者_JS百科ll using:

[DllImport("kernel32", SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hModule);

or just let the application termination handle it?


You should call FreeLibrary when you're done using a DLL that you loaded using LoadLibrary. 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 LoadLibrary to load a COM DLL and not using TLBIMP to create a .NET-accessible wrapper?

0

精彩评论

暂无评论...
验证码 换一张
取 消