Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with SendMessage/PostMessage

Posted on 1998-12-11
6
Medium Priority
?
448 Views
Last Modified: 2013-11-20
In my program I have a field where I can select some text in a editbox. That selection will then update some other fields  in my dialog.

To do that I have overloaded the editbox OnLButtonUp method, that method then posts a message to the parent dialog that recieves it and updates the proper fields...

It all works well in debug mode, but when I change to release mode it bombs out...

What is wrong with this?

Source for my OnLButtonUp function...

void CSmartCropEdit::OnLButtonUp(UINT nFlags, CPoint point)
{
    int start, end;
    CEdit::OnLButtonUp(nFlags, point);
    GetSel(start, end);
    if ((start != lastX) || (end != lastY)) {
        // Selection!
        GetParent()->PostMessage(WM_SMARTCHOPSELCHANGE);
        lastX = start;
        lastY = end;
    }
}

Messagehandler in the dialogbox...
void CCropRuleDlg::OnSmartCropSelChange()
{
   /* Yes, It is empty... But it doesn't matter
    * It crashes anyway...
    */
}

/Marre
0
Comment
Question by:marre111397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 2

Expert Comment

by:lucidity
ID: 1326057
I find PostMessage cause me grief sometimes, try SendMessage instead, it should have the same effect.

As for OnSmartCropSelChange in the Dialog, I dunno.
0
 
LVL 3

Expert Comment

by:plaroche
ID: 1326058
What does it do when it bombs out?
You can add debug info to your release build and you will be able to have a call stack and see the variables.
To achieve it add debug info in the C++ tab in the settings and ALSO in the link tab.
0
 
LVL 3

Accepted Solution

by:
plaroche earned 800 total points
ID: 1326059
Hell I just thought about it now, a good 20 mins after reading the question... must be friday! :-)

From your code it looks like your handler isn't declared correctly, make sure it is like this in your header file:

    afx_msg LONG OnAppMsg(WPARAM, LPARAM);

And in your implementation:

1: (message map)

    ON_MESSAGE(WM_USER_APPMSG, OnAppMsg)

2: (code)

LONG CMainFrame::OnAppMsg(WPARAM p1, LPARAM p2)
{
    CAppMsg *pAppMsg = (CAppMsg*)p1;
    m_pMsgMgr->NewMessage(pAppMsg);
    return 0;
}


This will fix your problem.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:plaroche
ID: 1326060
Why does this crash in release but not debug you say? Well it's because the MFC frameworks, when it calls message handlers via the message map, expects them to have a certain signature.  The call is then done by casting the function pointer to that expected signature. Since your doesn't match it crashes in release, a debug build is prevented from crashing.
0
 

Author Comment

by:marre111397
ID: 1326061
Thanks! An answer in less than 2h...

That really saved me a couple of hours... I tried to find an answer on dejanews, but I couldn't find any...
0
 
LVL 3

Expert Comment

by:plaroche
ID: 1326062
I even answered in less than an hour! ;-)  Good luck...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question