I’m writting a DLL in ANSI C and I’m using Curl to make HTTP connections.
This DLL should be able to connect to my server to send some info just before the application terminates. I would like to know what is the best approach to achieve this. I have tried registering a callback function using atexit and also calling the connectToServer method in a destructor. I also tried to use the DllMain with the DLL_PROCESS_DETACH. On all cases, Curl is unable to connect to server(error code 7) because windows already unloaded required libraries used by Curl.
I have heard people saying the only way to achieve this on Windows is to create a separate process(watchdog) to monitor when the main process terminates and then open the connection in this other process.
The library I’m writting works both on Linux (.so) and Windows (.dll). On Linux, i’m using atexit and everything works fine. I would prefer not to use a watchdog process since I won’t use it on the .so.
Is there a way to do this?
Thanks in advance.
You shouldn’t do anything in
DLL_PROCESS_DETACHfor exactly the reasons you’ve found. The best way to handle this is an explicit call from the application to say “I’m shutting down, do any clean up needed”.