I have an MFC based dialog application that uses CEvents, CSyncObjects and CMultiLocks to ensure that only one instance is running. This works fine.
If the user starts a second instance of the application by double clicking on an associated file, then the app recognises another instance is already running and posts a message to the first instance to load the file. The second instance then exits.
In the Debug version this works without problems.
In the Release version this works fine the first time an associated file is double clicked, but if I double click the same file again, the application fails with an exception in MFC42.dll.
I've determined that the line of code causing the error is the one that posts the message to the first instance of the application. I've put a try/catch block round the line to see if I can discover anything more, but no exception is caught. But if I comment the line out, no error.
As the first instance of the app also exits after the error - I'm inclined to think that the exception is occuring in the first instance as a result of the posted message. But if I put a try/catch block around the body of the message handler, there are no exceptions caught.
The following is the code used to find the main window of the first instance (after it is determined that another instance is running) and post the message:
HWND hMain = ::FindWindow("#32770", "MyApp");
::PostMessage(hMain, MY_MESSAGE, 0, 0);
Where should I be looking to track down the cause of this error?