Error 13 error C2440 when converting MFC6 app to MFC8...

Posted on 2007-10-12
Last Modified: 2013-12-14
I have an old MFC6 application that i have ported across to MFC 8 (2005).

It fails compilation with the following message

Error 13 error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMyAppName::* ) (WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' d:\source\MyApp\app1.cpp 164

The CPP file has the following:
LRESULT CMyAppName::OnMyMessage1(WPARAM wParam, LPARAM lParam)
   ULONG p1 = static_cast<ULONG> ( wParam );
   ULONG p2 = static_cast<ULONG> ( lParam );

the Header file has the following:
afx_msg LRESULT OnMyMessage1(WPARAM wParam, LPARAM lParam);
There are words about this all over the internet but no simple step guides as to how to convert it!

Any help would be appreciated.

Best regards,

Question by:jatkin
    LVL 14

    Accepted Solution

    Try changing ON_MESSAGE in your message map to ON_THREAD_MESSAGE.
    LVL 14

    Expert Comment

    You'll probably have to change your function to

    afx_msg void OnMyMessage1(WPARAM wParam, LPARAM lParam); // <- doesn't return anything

    If you have to have a return value, only solution I see is to push this function into a class that derives from CWnd.
    LVL 4

    Author Comment


    Thanks for the exceptionally fastest response!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now