CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to pass int return type function in ON_COMMAND of BEGIN_MESSAGE_MAP

  1. #1
    Join Date
    Oct 2019
    Posts
    82

    How to pass int return type function in ON_COMMAND of BEGIN_MESSAGE_MAP

    When member function whose return type is int is placed inside the ON_COMMAND of BEGIN_MESSAGE_MAP, It shows error of invalid type conversion. Suggest whats the alternative for that or how can i pass int return function .

    // MyFrame.h
    Code:
    afx_msg int func();
    //MyFrame.cpp
    Code:
    BEGIN_MESSAGE_MAP (MyFrame, CFrameWnd)
    ON_COMMAND (ID1,func)
    END_MESSAGE_MAP()

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

    Re: How to pass int return type function in ON_COMMAND of BEGIN_MESSAGE_MAP

    Why do you need the return value of this message handler?
    Victor Nijegorodov

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,598

    Re: How to pass int return type function in ON_COMMAND of BEGIN_MESSAGE_MAP

    How are you planning on getting the return value? How about just setting a member variable

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,607

    Re: How to pass int return type function in ON_COMMAND of BEGIN_MESSAGE_MAP

    Quote Originally Posted by Beginner_MFC View Post
    When member function whose return type is int is placed inside the ON_COMMAND of BEGIN_MESSAGE_MAP, It shows error of invalid type conversion.
    Yep, ON_COMMAND() macro expects the function to look like
    Code:
    afx_msg void func();
    Suggest whats the alternative for that or how can i pass int return function .
    The the only way to satisfy the compiler is to give it what it wants. In other words, you either change the func to return nothing or otherwise provide a wrapper function, something like that:

    Code:
    afx_msg int func();
    
    afx_msg void cmd_func()
    {
        int ret = func();
        TRACE("func() returned %d\n", ret);
    }
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)