Release Build crashes after PostThreadMessage call

My application seems to work fine as a Debug build, but when I build as release it is crashing after a PostThreadMessage call. I can avoid the crash by popping an AfxMessageBox right after the call to PostThreadMessage.


 pApp->PostThreadMessage(WM_USER_UPDATE_ALL,0,0);

#ifndef _DEBUG
  AfxMessageBox("this avoids crash in the Release Build?")
#endif

The message I get is:
The instruction at "0x00000" referenced memory at "0x000000". the memory could not be "read".


Any idea what I am doing wrong or what could be causing this?

Thanks,

-Eric

nielsewAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
Hi,

I think itis not getting time to update. So put the sleep after the call of PostThreadMessage.

pApp->PostThreadMessage(WM_USER_UPDATE_ALL,0,0);
Sleep(100);//U can vary this value to adjust the time

Then in the app class what r u doing in the message mapped function for WM_USER_UPDATE_ALL?. Is there somthing wrong like uninitialised pointers, not deleting the pointer....

U can post some relevant code, so that it will be clear.

VinExpert
0
nielsewAuthor Commented:
I gave that a try, with Sleep(2000); It still crashes.

I put a AfxMessageBox in the function being called by
WM_USER_UPDATE_ALL, and it never gets to that function.


-Eric
0
migelCommented:
Hi!
check declaration handler for WM_USER_UPDATE_ALL
I assume that this is your message declared through WM_USER constant
so your handler must be declared as:
LRESULT OnWM_USER_UPDATE_ALL(WPARAM, LPARAM);
and in the message map it must be associated with msgID like this:
ON_MESSAGE(WM_USER_UPDATE_ALL, OnWM_USER_UPDATE_ALL)
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

ToronadoCommented:
Hi nielsew,

So, if I understand you right, you do not reach the function you are trying to call?
Usually when you can solve a "release" bug by adding code, it is a stack related problem. In most cases the return address is overwritten.
You can try to "reserve" some stack space by declaring an array in the function you are trying to call.

regards,
 Toronado.
0
nv3prasadCommented:
I think Toronado is right.

one thing I found with sleep is it puts the whole thread to sleep, so if you have only the main thread then you are putting it to sleep and so you will get the same effect as without it.

Since the release build does not go through much of the code that debug code goes through so you may have timing problem too ( i.e, you might me sending a message to a class that is still not instantiated.

nv3prasad
0
WhaleCommented:
you can try to compile in release with the link incredemently option but I am not sure :)

Whale
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nicolay_ChCommented:
See this... May be this help you...
MSDN:

PRB: MFC Message Handler Not Called with PostThreadMessage()
Article ID: Q142415
0
ToronadoCommented:
Hi nielsew,

Does the link incrementally options realy help? If so, I think there is still something strange in your code causing the linker to make an error.
So, I don't think the problem is solved, only the symptoms are gone.

Be aware!

Regards,
 Toronado.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.