user3253797
user3253797

Reputation: 183

Extending COM class?

Hi I'm using Debenu Quick PDF Library in a PHP project. And I instantiate my object with the following code.

$qp = new COM('DebenuPDFLibraryAX1012.PDFLibrary');

My question : Is it possible to extend this COM class?

Upvotes: 3

Views: 48

Answers (2)

DarthGizka
DarthGizka

Reputation: 4675

Extending a COM class - in the sense of overriding some functions and expecting the base class code to call the overridden versions - is not possible in general, regardless of the language you are using.

The reason is simple: even though COM interfaces resemble the virtual pointer tables of C++ objects - to the point of the latter being usable as the former in some contexts - they are effectively unidirectional. They allow you to call into the object, but they are not necessarily used by the object to invoke its own methods, and COM does not allow you to stick a new function pointer in there somewhere.

In fact, unless the interface you are using is for an in-process object created in the same apartment, invocations of interface methods do not go directly to the object. Instead they go to a proxy object created by COM, which forwards the call to a stub object in the true object's apartment (which may be in another process, even on another computer), which will in turn invoke the method on the true object and pass results back along the chain.

When you override a function of a base class you generally do this with the expectation that the base class code will call back into your derived class. In COM, calling something entails obtaining an interface pointer and invoking some of its methods. However, your derived class does not expose any interface to COM that the base class would know about and ask for.

That is why extensible COM classes must publish interfaces - basically, hooks - that users can implement in order to get called back at appropriate times. These are often called 'event interfaces', and the COM class is then said to be 'publishing events', with 'OnClick' being a famous example.

Upvotes: 0

Mike Brant
Mike Brant

Reputation: 71422

Yes, it is possible to extend any class unless it is declared as final. You may not however be able to override certain methods if the individual methods have been declared with final keyword.

Upvotes: 1

Related Questions