-
April 1st, 2020, 09:50 PM
#1
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()
-
April 2nd, 2020, 01:48 AM
#2
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
-
April 2nd, 2020, 07:24 AM
#3
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
-
April 5th, 2020, 01:55 PM
#4
Re: How to pass int return type function in ON_COMMAND of BEGIN_MESSAGE_MAP
Originally Posted by Beginner_MFC
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|