troubleshooting Question

Tracking down ::PostMessage error

Avatar of devon-lad
devon-lad asked on
Editors IDEsSystem Programming
9 Comments2 Solutions293 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?

ASKER CERTIFIED SOLUTION
alexcohn

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 9 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 9 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004