I have a pointer to a form
form->DoStuff();
but the subclass of form is not being called despite the DoStuff() being
declared virtual in the base class. One thing that is interesting is that
the Subclass of form is declared/compiled inside an exe, whilst the base
class is inside a dll (assembly).
Is there a restriction on virtual calls not being propagated out of an
assembly an into another unit? (I notice that much of the framework
redeclares handlers for stuff, when a virtual call in the base class might
be better).
Any idea what I may have done wrong
Snippet follows. The callback is generated in an unmanaged dll, using a
GCHandle to point to the form.
void FormCallBackFn(AnObj *obj, unsigned long ID, void *self, void *data)
{
System::IntPtr handle = self;
GCHandle GCHandle = GCHandle::op_Explicit(handle);
MyWindow __gc *const thisPtr = dynamic_cast<MyWindow
__gc<*const>(GCHandle.Target);
if (!thisPtr) return;
switch (ID) {
case MyStuff::DoSomethingInteresting :
thisPtr->DoStuff(obj, data);
break;
default:
break;
}
}
thisPtr->DoStuff(obj, data); is always calling
BaseForm::DoStuff(obj, data);
and not
DerivedForm::DoStuff(obj, data);
(Thje debugger clearly shows that thisPtr is actually a derived class and
not a base one)
thanks
JB
John Biddiscombe - 07 May 2004 14:56 GMT
The problem was caused by the function definition
void FormCallBackFn(AnObj *obj, unsigned long ID, void *self, void *data)
in the subclass the overridden version obviously had a different signature
(class AnObj). Since you can't #include the base class in derived forms,
it's going to be hard to make the function signatures identical. I had to
use void * to solve my problem, then typecast back leter.
When
#include "baseclass.h"
is used in Forms, you get redefinition erros. Can anyone shed any light on
this issue?
thanks
JB
> I have a pointer to a form
>
[quoted text clipped - 42 lines]
>
> JB