Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send a message through socket fron DLL on application closing?
    text
    copied!<p>I have a DLL written in C++ to be consumed by our clients - third party developers in their applications. The DLL has some facilities in to connect to our company's servers through winsock and communicate with the servers on a specific protocol.</p> <p>The outstanding task is to send a kind of farewell message to the active server on application closing. But the only way of getting known about the event (application closing) I am aware about is DllMain/DLL_PROCESS_DETACH case. I know that it is not recommended, I read <a href="http://blogs.msdn.com/b/oldnewthing/archive/2012/01/05/10253268.aspx" rel="nofollow">Raymond Chen's article</a> about this and MSDN documentation, but instead of cautions I need a solution.</p> <p>Of course I did a try to send the message from DllMain, but it seemed that at that moment winsock library had been already detached, as what I received was WSANOTINITIALISED (10093) error.</p> <p>Also I tried to create a static finalizer like the following:</p> <pre><code>struct Finalization { ~Finalization() { // sending the message } }; static Finalization f; </code></pre> <p>without success either.</p> <p>I feel that what I need is somewhat like a trigger point to know, when the process is going to terminate. The case of simultaneous using the library can be ignored, as its specific leaves absolutely no sense in that.</p> <p>What I am thinking about is that the library is bundled with an interface header, that is going to be included in the customer's application. I could use the fact to place something in the file, a mutex or something like that.</p> <p>Maybe it's worth mentioning that the previous version of the library was written in Delphi, and the parting message was sending from one of finalization sections, and it worked perfectly, perhaps just by chance.</p> <p>Thank you in advance for your ideas.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload