I have a dll which is actually a com service that is registered and then being loaded by another .exe process. I would like when the user exit from the .exe to execute some resource closing steps from within my dll before it is too late. I tried to intercept the DLLPROCESSDETACH or DLLTHREADDETACH from the DllMain of my DLL but it seems when it gets there, it is already too late as the threads started by my DLL (which I need to execute the closing steps) have already stopped?! Of course, I do not control the .exe code otherwise I would have invoked from there a call to execute those clean closing steps before it exits. I can only work on the DLL itself. It doesn't seem the DllCanUnloadNow or the DllUnregisterServer get called either.
Has any one a work around for this situation?
Thank you many in advance for any inputs.