Solved

Problem with SendMessage/PostMessage

Posted on 1998-12-11
6
442 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 200 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 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