troubleshooting Question

Tracking down ::PostMessage error

Avatar of devon-lad
devon-lad asked on
System ProgrammingEditors IDEs
9 Comments1 Solution293 ViewsLast Modified:
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");
if (hMain)
{
     ::PostMessage(hMain, MY_MESSAGE, 0, 0);
}

Where should I be looking to track down the cause of this error?

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros