We have a DLL built in Visual Studio using C++11. Our DLL has a fixed API at this point, and it includes an open and close function (among others). We allow our users to open and close multiple times without closing the app. Inside our DLL, we are using a 3rd party library that has not only an open and close, but also an initialize and uninitialize.
The open and close map closely to our open and close, but the initialize and uninitialize are to be called only once each, at start up and shut down. I am able to call their initialize only once from our open function, but I cannot find a place to call the uninitialize, as I don't know when the app is about to be shut down. The most logical place to call it from is in the DllMain function under the DLL_PROCESS_DETACH, and while this works when running under debug, when I run under release we get an unhandled exception, "Fatal program exit requested." If I just give up and remove their uninitialize call, I still get an unhandled exception and in neither case do I cleanly shut down.
Is there any way to get a signal/notification that the application is shutting down prior to DLL_PROCESS_DETACH?