3

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?

3
  • Have you tried class MyCOM extends COM {} $qp = new MyCOM('DebenuPDFLibraryAX1012.PDFLibrary'); Commented Feb 7, 2014 at 23:05
  • Yes I tried it after your recommendation. But it didnt work. No method of COM class inherited. Commented Feb 7, 2014 at 23:16
  • In that case, you have the answer to your question Commented Feb 7, 2014 at 23:21

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.