Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing object pointers in callback/event methods

3 views
Skip to first unread message

gary.c...@virgin.net

unread,
Sep 24, 2008, 6:27:38 AM9/24/08
to
Hello,

I have a library object that indexes large data files of various
formats by converting to a common format.

During the indexing process i call a callback method so that an
interested consumer of the object can access the converted data at the
point of indexing.

The signature of my callback method has a parameter that is a pointer
to a common base class object from which all of my converter objects
are derived.

In my consumers implementation (a separate application) of the call
back function i use dynamic_cast to downcast the passed base pointer
object to the expected derived class. Although dynamic_cast does
succeed the resultant cast pointer does not hold the derived class
details. I suspect that only memory for the base class is actually
passed to the callback function.

Can anyone shed any light on how this should function? do i need to
provide custom marshalling? if so how?

Many thanks

gary.c...@virgin.net

unread,
Sep 24, 2008, 8:56:18 AM9/24/08
to

Ok, please ingore previous post, in actual fact in this scenario the
object and consumer are in the same process, something else must be
going on, more investigation required.

gary.c...@virgin.net

unread,
Sep 25, 2008, 11:20:29 AM9/25/08
to
> going on, more investigation required.- Hide quoted text -
>
> - Show quoted text -

Further to this, in case anyone has a similar experience. I finaly got
to the root of the problem.

In my callback method i receive a base pointer and use dynamic_cast to
downcast to the expeced specialisation. dynamic_cast succeeds and the
debugger correctly displays the content of the pointer. When i try and
assign any values pointed at to local variables garbage values were
actually being assigned.

We are using BCB2007 but only just and so we have converted a lot of
code from BCB2006. It turns out that by default BCB2007 creates a
project with the compilation option 'Integer-sized enums' set to
enabled by default, conversely BCB2006 sets this option to disabled by
default. So when we ported our existing projects this option remained
disabled and so they were incompatible with a new BCB2007 project.
Although the dynamic_cast succeeds i guess that the interpretation of
any enumerated values in the BCB2007 are treated as integers whereas
they were shorts in the BCB2006 built library and hence the content
was offset.

Something to keep in mind if you are porting anything to BCB2007...

0 new messages