The following code
CAppToolControlBar * pBar = STATIC_DOWNCAST( CAppToolControlBar, pRTC->CreateObject() );
will work correctly without assertion failures and create a true instance of your
CAppToolControlBar
class only if this class has
DECLARE_DYNCREATE
/
IMPLEMENT_DYNCREATE
or
DECLARE_SERIAL
/
IMPLEMENT_SERIAL
macros inserted into its declaration and implementation. If the line of code above is executed correctly without an assertion failure, then your application instantiates and creates a
CAppToolControlBar
object rather than a
CExtToolControlBar
object. But you wrote you had detected the presence of a
CExtToolControlBar
object instead of
CAppToolControlBar
. You should try to ensure whether a pointer to the
CExtToolControlBar
object detected during debugging in your project is the same
pBar
pointer created by the line of code above. The
CExtControlBar::Create()
method works equally with the
CExtControlBar
,
CExtToolControlBar
and your
CAppToolControlBar
classes and any other
CExtControlBar
-derived classes. This method is invoked for the already instantiated control bar object. You detect the type of object specified by this pointer during step by step debugging of some method of this object, you should open the
Watch window in your Visual Studio and review this pointer variable in it. Please expand the tree of this variable until the members of topmost base class become visible. This is the
CObject
class in the case of MFC/Prof-UIS classes. You will see a virtual table pointer as the first member of the
CObject
class. It should be
CAppToolControlBar::vtbl
rather than
CExtToolControlBar::vtbl
.