Re: Design question
Alexander Adam <contact@emiasys.com> wrote:
I got an internal set of CPP Klasses, like the following sample:
class A
{
public:
B* getB() { return new B(); }
void doSomethingWithB(B* in) { ... }
}
class B {..}
Now internally I am working with those classes but need to expose the
whole CPP Hierarchy into COM to use by scripting. I have a custom
IDispatchEx implementation to which I could expose methods to. The
biggest pain I have right now is that I of course cannot pass CPP
Class pointers around my COM objects.
Normally, you would wrap each of your classes in a separate COM object.
So you would have ComA and ComB, wrapping A and B. ComA::getB would call
A::getB, wrap the resulting B object in an instance of ComB, and return
an interface pointer implemented by the latter.
Each wrapper can also implement a private interface, e.g. IRawObject
with a method void* GetRawObject(), returning a pointer to the wrapped
class. For example, ComA::doSomethingWithB will accept an IDispatch
pointer (necessary to be callable by script). It would query it for
IRawObject, call GetRawObject and cast it to B*, then call
A::doSomethingWithB with this pointer.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925