Solved

Problem with SendMessage/PostMessage

Posted on 1998-12-11
6
436 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 97
fizzArray2 challenge 1 91
Problem to event 3 104
Message not shown 5 67
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

820 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