Solved

Problem with SendMessage/PostMessage

Posted on 1998-12-11
6
428 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:plaroche
Comment Utility
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
Comment Utility
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
Comment Utility
I even answered in less than an hour! ;-)  Good luck...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now