Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

Virtual functions not being called

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Biddiscombe - 07 May 2004 13:34 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.