How to know last process exited dll
I have dll which many process calls it.
In DLL_PROCESS_ATTACH I allocate shared memory for the first application to attach the thread and call InitializeCriticalSection.
In PROCESS_DETACH I want to call DeleteCriticalSection but only when the last process detach the dll. Is there anyway to do it without adding counter and wrapping it with criticalsection?
Note that I am using CreateFileMapping() and MapViewOfFile() to create the shared memory in DLL_PROCESS_ATTACH and call UnmapViewOfFile() and CloseHandle() in PROCESS_DETACH always. UnmapViewOfFile() is smart enough to know if there are still processes using this resource.
Thanks you for you help.