#1
  1. Don't fear the penguins!
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    arborlon.gingle.net
    Posts
    147
    Rep Power
    12

    VC++ Error C2440


    Can't seem to figure this one out. I have a message map that looks like this:

    Code:
    BEGIN_MESSAGE_MAP(CnetMonApp, CWinApp)
    	ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
    END_MESSAGE_MAP()
    OnTrayNotification looks like so:

    Code:
    LRESULT CnetMonApp::OnTrayNotification(WPARAM wParam, LPARAM lParam)
    {
    	return m_TrayIcon.OnTrayNotification(wParam, lParam);
    }
    and when I try to compile, it whines at me:

    Code:
    error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CnetMonApp::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
    Any help/clues/explanations would be appreciated :). Thanks!
    Every morning, I get up and look through the Forbes list of the richest people in America. If I'm not there, I go to work.

    May your Tongue stick to the Roof of your Mouth with the Force of a Thousand Caramels.

    To the systems programmer, users and applications serve only to provide a test load.
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Apparently you are trying to return a CnetMonApp instead of a CWnd (or perhaps vice versa). Check the actual return value for m_TrayIcon.OnTrayNotification(). You may be able to cast a CnetMonApp to a CWnd, maybe that will solve your problem. It is all MFC voodoo to me.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. Don't fear the penguins!
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    arborlon.gingle.net
    Posts
    147
    Rep Power
    12
    I've tried taking it out of the class, to no avail, so I don't think that it has something to do with that. But then again, I wouldnt know. I'm still very new to C++. The class that m_TrayIcon's an instance of (CSystemTray) was written by someone else, and is likely above me to understand. But what do you mean by 'cast'? Thanks for the help!
    Every morning, I get up and look through the Forbes list of the richest people in America. If I'm not there, I go to work.

    May your Tongue stick to the Roof of your Mouth with the Force of a Thousand Caramels.

    To the systems programmer, users and applications serve only to provide a test load.
  6. #4
  7. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    I detest MFC because of all the obscure code that is required just to get simple stuff to run. Of course, X is no better, I guess it is just the pain of using a windowing system. In any case, casting a variable is to tell the compiler you want to use this block of memory for something else. In this case you are dealing with classes and in most cases you can cast a class to the type of its parent class and use it as a member of that class. In this case I am speculating that CnetMonApp is an extention of CWnd and if that is so, you could cast the return into a type of CWnd (by adding "(CWnd *) just prior to the return). I am doing a lot of guessing here, but maybe it will help you in your research.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  8. #5
  9. Don't fear the penguins!
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    arborlon.gingle.net
    Posts
    147
    Rep Power
    12
    I don't think I like mfc much either... I've been having all sorts of problems, though I usually am able to figure things out. Anyways, is there a way I can use a message pump (like one that uses a while) instead of the messagemap thing? When my app starts, it doesn't have a window or dialog, but rather its just an icon in the system tray. Thanks.
    Every morning, I get up and look through the Forbes list of the richest people in America. If I'm not there, I go to work.

    May your Tongue stick to the Roof of your Mouth with the Force of a Thousand Caramels.

    To the systems programmer, users and applications serve only to provide a test load.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    So, what is the return type of CSystemTray::OnTrayNotification(WPARAM, LPARAM)?
  12. #7
  13. Don't fear the penguins!
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    arborlon.gingle.net
    Posts
    147
    Rep Power
    12
    It's LRESULT.
    Every morning, I get up and look through the Forbes list of the richest people in America. If I'm not there, I go to work.

    May your Tongue stick to the Roof of your Mouth with the Force of a Thousand Caramels.

    To the systems programmer, users and applications serve only to provide a test load.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Of course, I should have paid more attention to the error message.

    The error is because you're trying to implement a message handler in an application derived class, not a window derived class. The error occurrs because you can't cast your CnetMonApp * to a CWnd * since CWinApp does not inherit from CWnd in any way.

    Messages are a way to send information from window to window, or application to window, but not window to application. CWinApp derived classes can respond to commands (ON_COMMAND et al) for example, but not messages (ON_MESSAGE).
  16. #9
  17. Don't fear the penguins!
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    arborlon.gingle.net
    Posts
    147
    Rep Power
    12

    Lightbulb


    Ah, that makes some sense! Thanks for the help! I've sorta got everything in pieces on the floor atm, so I'll try changing that tommorrow and see what happens. Thanks!
    Every morning, I get up and look through the Forbes list of the richest people in America. If I'm not there, I go to work.

    May your Tongue stick to the Roof of your Mouth with the Force of a Thousand Caramels.

    To the systems programmer, users and applications serve only to provide a test load.
  18. #10
  19. Don't fear the penguins!
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    arborlon.gingle.net
    Posts
    147
    Rep Power
    12
    I changed it to ON_COMMAND, but now I have (surprise) another error to deal with. Though I think its related. Here's my message map:

    Code:
    BEGIN_MESSAGE_MAP(CnetMonApp, CWinApp)
    	ON_COMMAND(WM_ICON_NOTIFY, OnTrayNotification)
    END_MESSAGE_MAP()
    My function is prototyped as:

    Code:
    LRESULT OnTrayNotification(WPARAM wParam = 1, LPARAM lParam = 1);
    And the error is:

    Code:
    error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CnetMonApp::* )(WPARAM,LPARAM)' to 'AFX_PMSG'
    Did I just missunderstand what you were saying, or is it something else entirely?


    ... /me thinks me needs to figure out how to decipher these error messages ;) ...
    Every morning, I get up and look through the Forbes list of the richest people in America. If I'm not there, I go to work.

    May your Tongue stick to the Roof of your Mouth with the Force of a Thousand Caramels.

    To the systems programmer, users and applications serve only to provide a test load.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    The problem is the function pointer you passed to the ON_COMMAND macro doesn't match the pointer type expected by the framework. Command handlers should be prototyped like so:
    Code:
    void CMyObject::OnMyCommand(void)
    Your function doesn't match that prototype, since it's still the implementation of your initial ON_MESSAGE handler.
  22. #12
  23. Don't fear the penguins!
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    arborlon.gingle.net
    Posts
    147
    Rep Power
    12
    Ok, I think I gotcha. But now I'm not sure how to do this. I need this function so I can do the context menu off the icon. The example did it like this, but they had a window and used ON_MESSAGE. I need to do m_TrayIcon.OnTrayNotification(wParam, lParam);. Any ideas?

    Thanks for all the help!
    Every morning, I get up and look through the Forbes list of the richest people in America. If I'm not there, I go to work.

    May your Tongue stick to the Roof of your Mouth with the Force of a Thousand Caramels.

    To the systems programmer, users and applications serve only to provide a test load.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Well, you'll have to look at the documentation for this CSystemTray and find out what it expects for the WPARAM and LPARAM. As is the case with many window messages, they may be unused.

    If the handler expects data, it will be your responsibility to collect the data and pass it on through the parameters in your command handler. Otherwise, you could just pass NULL values to the handler.
    Last edited by MJEggertson; September 29th, 2003 at 05:58 PM.
  26. #14
  27. Don't fear the penguins!
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    arborlon.gingle.net
    Posts
    147
    Rep Power
    12
    Ok. Thanks for all the help!
    Every morning, I get up and look through the Forbes list of the richest people in America. If I'm not there, I go to work.

    May your Tongue stick to the Roof of your Mouth with the Force of a Thousand Caramels.

    To the systems programmer, users and applications serve only to provide a test load.

IMN logo majestic logo threadwatch logo seochat tools logo