On Detach

Since this is my semi-personal, semi-professional, semi-autobiographical, semi-graphomanical blog, I tend to write about anything relating to my life, my occupations, memories I might lose or just any random thought that comes across. Now, with a new job I’ve taken, I have found my occupations expanding a little bit. And during my work, I tend to look up solutions on line if the problem is more than I can handle. Sometimes I find them and sometimes I don’t. Sometimes it’s somewhere in between. So, if I come across a problem and I don’t see the solution clearly and can find help on line but end up eventually solving it, I will now try to explain it so, maybe, someone looking for the same solution later will have less of a problem.

This is why this post is in English, because I hope it will appeal to a wide audience. I will also attempt to use as many relevant keywords and will appreciate link backs to raise awareness or tips on how to write this better. Thanks. Also, since my work is proprietary and I am under NDA, I can’t really discuss what I’m working on. Thus, I will address problems in general terms only.

And now, to business. This problem occurred to me while I was working off files from a removable drive. We have a dialog box that refers to those files and the problem I had was that if the drive was removed while the dialog was open, the software crashed. The dialog was still open and was still trying to update itself with those files and experienced an access violation.

The solution was finding the exact detach process, the point in the flow the program goes to when it experiences a sudden drive removal, and calling for the dialog’s “OnExit” function. Once the dialog returns from being modal, I needed to destroy the instance of the window. But before doing that, I needed to make sure all processes on it were finished. So I made an Event we shall call a Termination Event, that I created and reset during construction. At the start of the destructor, I set a flag that called for termination and then waited on the termination event which would be set once updates have stopped. Once the event was set, I could return and completely destroy the dialog instance and set it to NULL.

That’s it. Now the dialog closes neatly, stops all updates and destroys itself before any damage is done. Hoped this help.

Next? How to compile the OpenSSL package for current-gen Visual Studio environments.


Posted in Programming by with comments disabled.