I have a C++ DLL project which contains a dllmain source file, a header with just the DLL function declarations, and a cpp file which contains the full function definitions, and a global pointer to an instance of a different class. This pointer is initialised with a call to an Init function, and all the rest of the DLL functions use the pointer and return an error if it has not been allocated.
Other than relying on the user to call a specific function when they're finished with the DLL (which sounds like a terrible idea) how can I make sure that the global pointer in the cpp file is deallocated?
Thanks.
When the DLL is being shut down there will be a call to
DllMain
with a parameter ofDLL_PROCESS_DETACH
; you can put code to free your global there.