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()
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?
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
Re: How to pass int return type function in ON_COMMAND of BEGIN_MESSAGE_MAP
Quote:
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();
Quote:
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);
}