C6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' <P>Help Needed:</P> <P>I'm moving a program from C6.0 to Visual Studio 2005 C++.&nbsp; It's an MFC program.&nbsp; The problem I am having is with ON_MESSAGE handling user messages.&nbsp; The compiler is not happy with the function prototype for the message handler.&nbsp; I've made the needed changes to the code to satisfy the stronger type checking of this compliler, but don't understand the 'static_cast' comment.&nbsp; I've tried making the function 'static', but it makes no difference to the compiler.</P> <P><FONT size=2><STRONG><FONT size=3>[from acquiredoc.h]</FONT></STRONG></P><FONT color=#0000ff> <P>public</FONT>:</P> <P>afx_msg LRESULT OnSetCameraParms(WPARAM w, LPARAM l); </P> <P><STRONG><FONT size=3>[from acquiredoc.cpp, lines 135-140]</FONT></STRONG></P> <P>BEGIN_MESSAGE_MAP(CAcquireDoc, CDocument)</P> <P><FONT color=#008000>//{{AFX_MSG_MAP(CAcquireDoc)</P></FONT> <P><FONT color=#008000>//}}AFX_MSG_MAP</P> <P>// ON_COMMAND_RANGE(IDM_GET_IMAGE_A, IDM_GET_IMAGE_C, OnGetImage)</P></FONT> <P>ON_MESSAGE(WM_USER_MSG_IDM_PARMS, OnSetCameraParms)&nbsp;-- the problem line --</P> <P>END_MESSAGE_MAP()</P> <P><STRONG><FONT size=3>The compiler generates the following error:</FONT></STRONG></P><FONT size=1> <P><FONT size=2>acquiredoc.cpp(139) : error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CAcquireDoc::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'</FONT></P> <P><FONT size=2>None of the functions with this name in scope match the target type</FONT></P> <P><FONT size=3>I've seen many comments about this problem in other postings.&nbsp; I've implemented the recommended changes, but still have not managed to overcome this issue.&nbsp; What am I missing?</FONT></P> <P><FONT size=2></FONT>&nbsp;</P> <P>&nbsp;</P></FONT></FONT>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z8ca87560-2819-4c10-8127-8e2f214b14fchttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#8ca87560-2819-4c10-8127-8e2f214b14fchttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#8ca87560-2819-4c10-8127-8e2f214b14fcLes06291979http://social.msdn.microsoft.com/Profile/en-US/?user=Les06291979C6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' <P>Help Needed:</P> <P>I'm moving a program from C6.0 to Visual Studio 2005 C++.&nbsp; It's an MFC program.&nbsp; The problem I am having is with ON_MESSAGE handling user messages.&nbsp; The compiler is not happy with the function prototype for the message handler.&nbsp; I've made the needed changes to the code to satisfy the stronger type checking of this compliler, but don't understand the 'static_cast' comment.&nbsp; I've tried making the function 'static', but it makes no difference to the compiler.</P> <P><FONT size=2><STRONG><FONT size=3>[from acquiredoc.h]</FONT></STRONG></P><FONT color=#0000ff> <P>public</FONT>:</P> <P>afx_msg LRESULT OnSetCameraParms(WPARAM w, LPARAM l); </P> <P><STRONG><FONT size=3>[from acquiredoc.cpp, lines 135-140]</FONT></STRONG></P> <P>BEGIN_MESSAGE_MAP(CAcquireDoc, CDocument)</P> <P><FONT color=#008000>//{{AFX_MSG_MAP(CAcquireDoc)</P></FONT> <P><FONT color=#008000>//}}AFX_MSG_MAP</P> <P>// ON_COMMAND_RANGE(IDM_GET_IMAGE_A, IDM_GET_IMAGE_C, OnGetImage)</P></FONT> <P>ON_MESSAGE(WM_USER_MSG_IDM_PARMS, OnSetCameraParms)&nbsp;-- the problem line --</P> <P>END_MESSAGE_MAP()</P> <P><STRONG><FONT size=3>The compiler generates the following error:</FONT></STRONG></P><FONT size=1> <P><FONT size=2>acquiredoc.cpp(139) : error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CAcquireDoc::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'</FONT></P> <P><FONT size=2>None of the functions with this name in scope match the target type</FONT></P> <P><FONT size=3>I've seen many comments about this problem in other postings.&nbsp; I've implemented the recommended changes, but still have not managed to overcome this issue.&nbsp; What am I missing?</FONT></P> <P><FONT size=2></FONT>&nbsp;</P> <P>&nbsp;</P></FONT></FONT>Tue, 25 Apr 2006 13:47:32 Z2006-04-26T12:33:37Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#9d3e8045-25c7-499c-b89e-099bf78bd8e6http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#9d3e8045-25c7-499c-b89e-099bf78bd8e6Jonathan Caves - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Jonathan%20Caves%20-%20MSFTC6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' <p>I suspect that this line:</p> <p>ON_MESSAGE(WM_USER_MSG_IDM_PARMS, OnSetCameraParms) </p> <p>should be something like:</p> <p>ON_MESSAGE(WM_USER_MSG_IDM_PARMS, &amp;XXX::OnSetCameraParms) </p> <p>where XXX is the class in which OnSetCameraParams is defined.</p>Wed, 26 Apr 2006 00:54:55 Z2006-04-26T00:54:55Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#2dd5fe2f-3eb4-4bf0-bb3c-9ed5cc5eee1chttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#2dd5fe2f-3eb4-4bf0-bb3c-9ed5cc5eee1cMartin Richterhttp://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20RichterC6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' <p>CDocumets can handle only ON_COMMAND messages. Windows messges are not possible and they doesn't make sense, because a CDocuent has no WndProc!</p> <p>This might be a relict from old VC6 times were message maps and their handlers were not checked properly. Also I suppose that this code was never called and used.</p>Wed, 26 Apr 2006 08:30:21 Z2006-04-26T12:45:36Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#65c22fe5-ba11-4d83-a25d-af2944475d4chttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#65c22fe5-ba11-4d83-a25d-af2944475d4cLes06291979http://social.msdn.microsoft.com/Profile/en-US/?user=Les06291979C6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' <p>I tried several flavors of that idea yesterday to no avail.  But I have to confess that I didn't try the &amp;.</p> <p>The problem is solved. If you could take a look at the next reply, I'll go into details.</p> <p>Thanks for the assist.</p> <p>Les</p>Wed, 26 Apr 2006 12:11:00 Z2006-04-26T12:11:00Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#856b84ee-aa08-4fbb-bd33-2df7385660ffhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#856b84ee-aa08-4fbb-bd33-2df7385660ffLes06291979http://social.msdn.microsoft.com/Profile/en-US/?user=Les06291979C6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' <p>Truth is stranger than fiction.</p> <p>I spent a great deal of time yesterday looking for other solutions.  The result I posted in my original posting is the CORRECT solution.  However, as luck would have it, the first errors were showing up in a CDocument Class.</p> <p>As you noted, CDocument does not process ON_MESSAGE, but C6.0 never complained about this.  I checked the two handlers I had in the CDocument class and it is true.  They were never used.</p> <p>I have removed the unused handlers, made the correct prototype changes to all the remaining functions that are acccessed via ON_MESSAGE and the program compiles and runs.  Now to see if it still runs correctly.</p> <p>Thanks,</p> <p>Les</p> <p>P.S. Just for future reference for any other who may read this:</p> <p>ON_MESSAGE connot be handled by CDocument classes.</p> <p>The prototype in the header file should look like this:</p><font size=2> <p>afx_msg LRESULT functionname(WPARAM, LPARAM);</p> <p><strong><font size=3>Example </font></strong></p> <p><strong>(from AcquireFrame.h)</strong></p><font color="#0000ff"> <p>public</font>:</p> <p>afx_msg LRESULT OnShowAcqWindow(WPARAM, LPARAM);</p> <p><strong>(from AcquireFrame.cpp)</strong></p> <p>BEGIN_MESSAGE_MAP(CAcquireFrame, CMDIChildWnd)</p> <p>ON_MESSAGE(WM_SHOW_ACQUIRE_WINDOW, OnShowAcqWindow)</p> <p>END_MESSAGE_MAP()</p> <p> </p><font size=2> <p>LRESULT CAcquireFrame::OnShowAcqWindow(WPARAM w, LPARAM l)</p> <p>{</p> <p>ActivateFrame();</p> <p></font><font color="#0000ff" size=2>return</font><font size=2> 0;</p> <p>}</p></font> <p> </p></font>Wed, 26 Apr 2006 12:32:17 Z2006-04-26T12:33:37Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#5fc7dd21-1d77-4717-9b89-dfa82f0006e2http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#5fc7dd21-1d77-4717-9b89-dfa82f0006e2Mandanahttp://social.msdn.microsoft.com/Profile/en-US/?user=MandanaC6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' <p>Thanks alot, It really helped me and you explained it in wonderful format.</p> <p>I appriciate it. you Saved my time and I feel great.<img src="images/emoticons/smile_regular.gif"></p>Thu, 15 Jun 2006 17:13:27 Z2006-06-15T17:13:27Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#69161268-38b5-4182-a7ca-76e18186efa9http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#69161268-38b5-4182-a7ca-76e18186efa9Les06291979http://social.msdn.microsoft.com/Profile/en-US/?user=Les06291979C6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' Thanks.  But without the help I was given, it wouldn't have been possible.   I'm glad  I took the time to summarize what others told me.<br><br>Les <br>Fri, 16 Jun 2006 10:48:39 Z2006-06-16T10:48:39Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#92a7262c-2494-4730-b313-532a689f0df4http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8ca87560-2819-4c10-8127-8e2f214b14fc#92a7262c-2494-4730-b313-532a689f0df4Bin Zhouhttp://social.msdn.microsoft.com/Profile/en-US/?user=Bin%20ZhouC6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast' <p>Thanks a lot.</p> <p><font face=Verdana>I tried several post sites until find your post!</font></p> <p>wishes,</p> <p>Bin</p>Sat, 03 Feb 2007 14:19:18 Z2007-02-03T14:19:18Z