Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

'static_cast' : cannot convert from 'void error

Posted on 2009-05-11
4
Medium Priority
?
1,332 Views
Last Modified: 2013-12-21
I am converting an eVC++ project to VS2005.
The ON_MESSAGE(...) line below
BEGIN_MESSAGE_MAP(CBegin, CDialog)
//{{AFX_MSG_MAP(CBegin)
ON_MESSAGE(WM_USER_REFRESH_FULLSCREEN, OnFullScreenRefresh)

gives the error:
error C2440: 'static_cast' : cannot convert from 'void (__cdecl CBegin::* )(void)' to 'LRESULT (__cdecl CWnd::* )(WPARAM,LPARAM)'      

How do I solve this?
0
Comment
Question by:Wanting2LearnMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 800 total points
ID: 24354351
Change OnFullScreenRefresh() to

LRESULT CBegin::OnFullScreenRefresh( WPARAM wParam, LPARAM lParam )
{
   ...

   return 0L;
}


May be macro ON_MESSAGE is changed.
0
 
LVL 24

Assisted Solution

by:alexey_gusev
alexey_gusev earned 400 total points
ID: 24354491
ON_MESSAGE ()  macro always was with LRESULT foo(WPARAM, LPARAM), so older versions of MFC allowed some freedom, but no more
0
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 800 total points
ID: 24355353
MFC older version have different behavior because ON_MESSAGE macros are different (look at the cast)...
 // old
 #define ON_MESSAGE(message, mbrFn) \
     {message, 0, 0, 0, AfxSig_lwl, \
     (AFX_PMSG)(AFX_PMSGW)(LRESULT \
     (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))&mbrFn },
 
 // new 
 #define ON_MESSAGE(message, memberFxn) \
    { message, 0, 0, 0, AfxSig_lwl, \
        (AFX_PMSG)(AFX_PMSGW) \
        (static_cast< LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM) > \
        (memberFxn)) },

Open in new window

0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 800 total points
ID: 24357148
>>>> have different behavior because ON_MESSAGE macros are different (look at the cast)...

To add to above information:

A C cast was able to *cast off* the arguments of a function pointer while C++ static_cast requires same argument list of the function being casted and the cast only turns the class from YourDialogClass to CWnd (what is a baseclass).

The issue is that the call from DispatchMessage actually passed WPARAM and LPARAM arguments at the stack but your function doesn't have arguments. One could think of problems when unrolling the stack but it should have no consequences cause the stack was freed by the caller  (and not by the callee).

Things were different if your function would have 3 arguments. Then the last argument actually was not supported by the caller and if your function would access it nevertheless it would access some undefined (arbitrary) memory address what even could lead to a crash.

So, the above is a sample where a static_cast has advantages before a C cast with the constraint that a function with lesser arguments would need a different cast or must get some dummy arguments not actually needed just to please the compiler ...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question