How to clear .NET material when unloading C ++ / CLI DLLs?

I am new to C ++ / CLI, so please bear with me ...

I am working on a mixed C ++ / CLI DLL, which should act as a bridge between the Win32 process and the .NET assembly. In a DLL, I need some .NET material to be present throughout the life of the DLL. Initialization is not such a big problem, but I could not figure out when I can safely clear .NET stuff. Common C ++ objects (DLL_PROCESS_DETACH, global variables and static locals d'tors) seem to be called after the CLR leaves.

So, how can I get a notification that the DLL is about to disconnect from the CLR, so I can release the .NET links that I have?

+5
source share
4 answers

Well, the answer to my own question seems uncomfortable, but it was not suggested by someone else, and this is what I was looking for ... like this:

it turns out that Microsoft offers an exotic onexit change called _ onexit_m , which should be used in mixed-mode DLLs. When using _ onexit_m to register a (managed) callback function, this function will be called when the DLL is unloaded, but before the CLR was closed. It is similar to AppDomain.DomainUnload proposed by Ben Voigt , but for some reason I couldn’t get DomainUnload working, and _onexit_m is easier to use IMHO.

+2
source

AppDomain, AppDomain.DomainUnload, .

STW, AppDomain, - AppDomain.

AppDomains, ( ). , , , .

+2

++.NET, , , CLR - AppDomain; , AppDomain, , , AppDomain, .

0

.NET Dll ref. ref , . Dispose .

Each C ++ / CLI class that has some resources of its own or one-time class members must have a destructor and an optional finalizer. In particular, .NET links are published in the class destructor, which maps to the C # Dispose method.

0
source

All Articles