CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2006
    Posts
    231

    MFC Message maps

    Is it possible to use MFC's message mapping macros without Microsoft's extensions to the C++ language?

    I'm having some troubles, for example with Clang:

    Code:
    error: call to non-static member function without an object argument
      ON_MESSAGE(WM_UPDATEUISTATE, OnUpdateUIState)
                                   ^
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\atlmfc\include\afxmsg_.h
    expanded from macro 'ON_MESSAGE'
                    (memberFxn)) },
                     ^

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC Message maps

    What do you mean by "without Microsoft's extensions to the C++ language"?
    Is your project a MFC one or not?
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2006
    Posts
    231

    Re: MFC Message maps

    Yes, it's a MFC project and it compiles with the Visual C++ compiler.

    However, I'd like to use Clang-Tidy on the code base. It requires that the code can be parsed by the Clang compiler, but it only succeeds if the message maps are removed.

    So, the message maps depend on some non-standard or non-portable feature? Looking for an explanation...
    Last edited by TubularX; November 4th, 2017 at 01:11 PM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC Message maps

    Quote Originally Posted by TubularX View Post
    Yes, it's a MFC project and it compiles with the Visual C++ compiler.

    However, I'd like to use Clang-Tidy on the code base. It requires that the code can be parsed by the Clang compiler, but it only succeeds if the message maps are removed.

    So, the message maps depend on some non-standard or non-portable feature? Looking for an explanation...
    Sorry, I have no idea what "Clang-Tidy on the code base" is and how it works...
    And yes, message maps belong to MFC and its portability should depend upon how the destination environment them treats.

    Perhaps you will need to override the window procedure to handle the messages in Clang-Tidy environment...
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2006
    Posts
    231

    Re: MFC Message maps

    "Clang-Tidy is a clang-based C++ linter tool. Its purpose is to provide an extensible framework for diagnosing and fixing typical programming errors, like style violations, interface misuse, or bugs that can be deduced via static analysis."

    So, it's just analyzing the source code. It doesn't try to link anything. It doesn't try to build an executable.

    If MFC is C++ standard conformant, I don't understand why the treatment differs in the message map macro.

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: MFC Message maps

    Check if OnUpdateUIState has the corect prototype. If is mapped by using ON_MESSAGE macro, it must be
    Code:
       afx_msg LRESULT OnUpdateUIState(WPARAM wParam, LPARAM lParam);
    Also, is not bad to replace
    Code:
       ON_MESSAGE(WM_UPDATEUISTATE, OnUpdateUIState)
    with
    Code:
       ON_MESSAGE(WM_UPDATEUISTATE, &CYourClassName::OnUpdateUIState)
    Or, a little bit better, use (class) wizard which correctly maps WM_UPDATEUISTATE using ON_WM_UPDATEUISTATE macro, preventing programmers' mistakes.

    And BTW: Visual Studio has its own built-in code analysis support (have a look at "Analyze/Run Code Analysis" menu).
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC Message maps

    Quote Originally Posted by TubularX View Post
    Yes, it's a MFC project and it compiles with the Visual C++ compiler.

    However, I'd like to use Clang-Tidy on the code base. It requires that the code can be parsed by the Clang compiler, but it only succeeds if the message maps are removed.

    So, the message maps depend on some non-standard or non-portable feature? Looking for an explanation...
    You can install the MFC source code by changing your VS setup. Then you can drill down into the MFC message map macros and have a look for yourself.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured