3rd parameter of OnUpdate is a pointer to CObject. The pointer must be downcasted in the view class that implements its own OnUpdate. What is the best way to check if the cast succeed? Use CObject::IsKindOf or dynamic_cast? Is it OK to use RTTI in MFC projects?
3rd parameter of OnUpdate is a pointer to CObject . The pointer must be
Share
If you created your view using the wizards, then it will have put a DECLARE_DYNCREATE in the header file of your view class. If you created it by hand, I would make sure it has a DECLARE_DYNCREATE in the class definition of your view’s header file (or at least a DECLARE_DYNAMIC or DECLARE_SERIAL–DECLARE_SERIAL is generally overkill for a view class).
THen, when you want to downcast use the DYNAMIC_DOWNCAST macro and test for not NULL on return.
CView* pView = DYNAMIC_DOWNCAST(CView, pObject); // is one usage
Don’t listen to advice to not use the MFC macro because it’s not portable… If you’re writing a CView derived class, it’s already not portable–unless you use a toolkit like Wind/U, and then DYNAMIC_DOWNCAST will be portable as well.