Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ON_MESSAGE .NET Issue

ON_MESSAGE .NET Issue

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studioquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ryan B
    wrote on last edited by
    #1

    I am opening and compiling some old code in Visual Studio .NET I've run into a compiling problem..

    BEGIN_MESSAGE_MAP(CChildView,CWnd )
    	//{{AFX_MSG_MAP(CChildView)
    	ON_WM_PAINT()
    	ON_WM_CREATE()
    	ON_WM_ERASEBKGND()
    	ON_WM_SIZE()
    	//}}AFX_MSG_MAP
    	ON_MESSAGE(WM_FLIPWINDOW, OnFlipWindow)
    END_MESSAGE_MAP()
    

    tells me: error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChildView::* )(void)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' whats happening here? the Member Function is: void CChildView::OnFlipWindow() Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

    F M 2 Replies Last reply
    0
    • R Ryan B

      I am opening and compiling some old code in Visual Studio .NET I've run into a compiling problem..

      BEGIN_MESSAGE_MAP(CChildView,CWnd )
      	//{{AFX_MSG_MAP(CChildView)
      	ON_WM_PAINT()
      	ON_WM_CREATE()
      	ON_WM_ERASEBKGND()
      	ON_WM_SIZE()
      	//}}AFX_MSG_MAP
      	ON_MESSAGE(WM_FLIPWINDOW, OnFlipWindow)
      END_MESSAGE_MAP()
      

      tells me: error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChildView::* )(void)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' whats happening here? the Member Function is: void CChildView::OnFlipWindow() Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

      F Offline
      F Offline
      Fazlul Kabir
      wrote on last edited by
      #2

      MFC7 (in VS .NET) uses stricter type checking with message map macros. It looks like you need to replace the return from ‘void’ to ‘LRESULT’. Also make sure you supply the correct function parameters, such as (WPARAM, LPARAM) etc. More on this here [click on Microsoft Foundation Class (MFC) link] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcedit/html/vcrefWhatsNewLibrariesVisualC70.asp[^] Static Casting and MFC Message Maps Beginning with Visual C++ .NET, MFC provides stricter type checking for return and parameter types of message handler functions. This new behavior notifies the developer of potential problems by flagging potentially unsafe message handlers with an error message. MFC now uses static casts for ON_MESSAGE, ON_REGISTERED_MESSAGE, ON_THREAD_MESSAGE, and ON_REGISTERED_THREAD_MESSAGE. For example, in the past a developer could use a member function that returned void instead of LRESULT for ON_MESSAGE or ON_REGISTERED_MESSAGE and compile without any errors. With Visual C++ .NET, the potential miscast is caught and flagged as an error. The developer can fix the potential problem by replacing the return type (with LRESULT) and recompiling. Hope this helps. // Fazlul


      Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

      N 1 Reply Last reply
      0
      • F Fazlul Kabir

        MFC7 (in VS .NET) uses stricter type checking with message map macros. It looks like you need to replace the return from ‘void’ to ‘LRESULT’. Also make sure you supply the correct function parameters, such as (WPARAM, LPARAM) etc. More on this here [click on Microsoft Foundation Class (MFC) link] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcedit/html/vcrefWhatsNewLibrariesVisualC70.asp[^] Static Casting and MFC Message Maps Beginning with Visual C++ .NET, MFC provides stricter type checking for return and parameter types of message handler functions. This new behavior notifies the developer of potential problems by flagging potentially unsafe message handlers with an error message. MFC now uses static casts for ON_MESSAGE, ON_REGISTERED_MESSAGE, ON_THREAD_MESSAGE, and ON_REGISTERED_THREAD_MESSAGE. For example, in the past a developer could use a member function that returned void instead of LRESULT for ON_MESSAGE or ON_REGISTERED_MESSAGE and compile without any errors. With Visual C++ .NET, the potential miscast is caught and flagged as an error. The developer can fix the potential problem by replacing the return type (with LRESULT) and recompiling. Hope this helps. // Fazlul


        Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

        N Offline
        N Offline
        Nick Hodapp
        wrote on last edited by
        #3

        FYI, this feature alleviates the #1 programmer bug in MFC code. -Nick This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.

        1 Reply Last reply
        0
        • R Ryan B

          I am opening and compiling some old code in Visual Studio .NET I've run into a compiling problem..

          BEGIN_MESSAGE_MAP(CChildView,CWnd )
          	//{{AFX_MSG_MAP(CChildView)
          	ON_WM_PAINT()
          	ON_WM_CREATE()
          	ON_WM_ERASEBKGND()
          	ON_WM_SIZE()
          	//}}AFX_MSG_MAP
          	ON_MESSAGE(WM_FLIPWINDOW, OnFlipWindow)
          END_MESSAGE_MAP()
          

          tells me: error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChildView::* )(void)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' whats happening here? the Member Function is: void CChildView::OnFlipWindow() Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Look at what the error is telling you. The compiler is expecting a function that takes two params, but you're giving it a function that takes no params. The return type is also wrong. Add the two standard message params (WPARAM and LPARAM) and correct the return value. --Mike-- Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups