Discussion:
Passing object pointers in callback/event methods
(too old to reply)
g***@virgin.net
2008-09-24 10:27:38 UTC
Permalink
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
g***@virgin.net
2008-09-24 12:56:18 UTC
Permalink
Post by g***@virgin.net
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
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.
g***@virgin.net
2008-09-25 15:20:29 UTC
Permalink
Post by g***@virgin.net
Post by g***@virgin.net
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
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.- 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...
Loading...