For example if you have a simple managed console app and a simple unmanaged C++ DLL. You pInvoke into a function in the C++ DLL, does the DLL stay loaded in the unmanaged process until said process comes down? Or does the DLL get unloaded at the completion of every pInvoke call?
Asked
Active
Viewed 343 times
1 Answers
2
It stays in memory unless you explicity tell it to unload.

Joel Lucsy
- 8,520
- 1
- 29
- 35
-
1Thanks, can you point to any reference for this? Just wondering as I couldn't find it stated anywhere explicitely. – Rhubarb Oct 13 '10 at 02:16
-
@Rhubarb Per [Consuming Unmanaged DLL Functions](https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions): "***Locating and loading the DLL**, and locating the address of the function in memory **occur only on the first call** to the function.*" Which implies that the DLL is loaded only one time and is kept loaded for subsequent calls into the same DLL. That means the DLL is never unloaded (not by .NET anyway, but [can be done manually](https://stackoverflow.com/questions/2445536/)) – Remy Lebeau Aug 24 '21 at 17:47