Microsoft Developer Network > 포럼 홈 > Visual C++ Language > C6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast'
질문하기질문하기
 

답변됨C6.0->VS2005 -user messsages- ON_MESSAGE error C2440: 'static_cast'

  • 2006년 4월 25일 화요일 오후 1:47Les06291979 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Help Needed:

    I'm moving a program from C6.0 to Visual Studio 2005 C++.  It's an MFC program.  The problem I am having is with ON_MESSAGE handling user messages.  The compiler is not happy with the function prototype for the message handler.  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.  I've tried making the function 'static', but it makes no difference to the compiler.

    [from acquiredoc.h]

    public:

    afx_msg LRESULT OnSetCameraParms(WPARAM w, LPARAM l);

    [from acquiredoc.cpp, lines 135-140]

    BEGIN_MESSAGE_MAP(CAcquireDoc, CDocument)

    //{{AFX_MSG_MAP(CAcquireDoc)

    //}}AFX_MSG_MAP

    // ON_COMMAND_RANGE(IDM_GET_IMAGE_A, IDM_GET_IMAGE_C, OnGetImage)

    ON_MESSAGE(WM_USER_MSG_IDM_PARMS, OnSetCameraParms) -- the problem line --

    END_MESSAGE_MAP()

    The compiler generates the following error:

    acquiredoc.cpp(139) : error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CAcquireDoc::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'

    None of the functions with this name in scope match the target type

    I've seen many comments about this problem in other postings.  I've implemented the recommended changes, but still have not managed to overcome this issue.  What am I missing?

     

     

답변

  • 2006년 4월 26일 수요일 오전 8:30Martin RichterMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    CDocumets can handle only ON_COMMAND messages. Windows messges are not possible and they doesn't make sense, because a CDocuent has no WndProc!

    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.

  • 2006년 4월 26일 수요일 오후 12:32Les06291979 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    Truth is stranger than fiction.

    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.

    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.

    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.

    Thanks,

    Les

    P.S. Just for future reference for any other who may read this:

    ON_MESSAGE connot be handled by CDocument classes.

    The prototype in the header file should look like this:

    afx_msg LRESULT functionname(WPARAM, LPARAM);

    Example

    (from AcquireFrame.h)

    public:

    afx_msg LRESULT OnShowAcqWindow(WPARAM, LPARAM);

    (from AcquireFrame.cpp)

    BEGIN_MESSAGE_MAP(CAcquireFrame, CMDIChildWnd)

    ON_MESSAGE(WM_SHOW_ACQUIRE_WINDOW, OnShowAcqWindow)

    END_MESSAGE_MAP()

     

    LRESULT CAcquireFrame::OnShowAcqWindow(WPARAM w, LPARAM l)

    {

    ActivateFrame();

    return 0;

    }

     

모든 응답

  • 2006년 4월 26일 수요일 오전 12:54Jonathan Caves - MSFT중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I suspect that this line:

    ON_MESSAGE(WM_USER_MSG_IDM_PARMS, OnSetCameraParms) 

    should be something like:

    ON_MESSAGE(WM_USER_MSG_IDM_PARMS, &XXX::OnSetCameraParms) 

    where XXX is the class in which OnSetCameraParams is defined.

  • 2006년 4월 26일 수요일 오전 8:30Martin RichterMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    CDocumets can handle only ON_COMMAND messages. Windows messges are not possible and they doesn't make sense, because a CDocuent has no WndProc!

    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.

  • 2006년 4월 26일 수요일 오후 12:11Les06291979 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I tried several flavors of that idea yesterday to no avail.  But I have to confess that I didn't try the &.

    The problem is solved. If you could take a look at the next reply, I'll go into details.

    Thanks for the assist.

    Les

  • 2006년 4월 26일 수요일 오후 12:32Les06291979 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    Truth is stranger than fiction.

    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.

    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.

    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.

    Thanks,

    Les

    P.S. Just for future reference for any other who may read this:

    ON_MESSAGE connot be handled by CDocument classes.

    The prototype in the header file should look like this:

    afx_msg LRESULT functionname(WPARAM, LPARAM);

    Example

    (from AcquireFrame.h)

    public:

    afx_msg LRESULT OnShowAcqWindow(WPARAM, LPARAM);

    (from AcquireFrame.cpp)

    BEGIN_MESSAGE_MAP(CAcquireFrame, CMDIChildWnd)

    ON_MESSAGE(WM_SHOW_ACQUIRE_WINDOW, OnShowAcqWindow)

    END_MESSAGE_MAP()

     

    LRESULT CAcquireFrame::OnShowAcqWindow(WPARAM w, LPARAM l)

    {

    ActivateFrame();

    return 0;

    }

     

  • 2006년 6월 15일 목요일 오후 5:13Mandana 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Thanks alot, It really helped me and you explained it in wonderful format.

    I appriciate it. you Saved my time and I feel great.

  • 2006년 6월 16일 금요일 오전 10:48Les06291979 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.

    Les
  • 2007년 2월 3일 토요일 오후 2:19Bin Zhou 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Thanks a lot.

    I tried several post sites until find your post!

    wishes,

    Bin