Solved

Problem with SendMessage/PostMessage

Posted on 1998-12-11
6
434 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to ask for filename column 8 37
Named range not carried over 10 63
substring method in java 1 119
Sed question 2 84
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…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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