How to using the second IDispatch of a COM object in VBScript
-
I design a COM object by ATL, which has two IDispath. Default dispatch is IPlot2D, and the second is IMIDraw. IMIDraw has a method Plot(), how do I launch Plot() method?
You can not. There is a rule(standard) of COM which states that you can only have one dispatch interface in the COM object. The reason for that is that late binding clients(VBS) use QueryInterface(IDispatch)/Invoke(methodID) for everything. 1. You can try to implement IMIDraw as separate object and expose it through a method of IPlot2D. 2. If they are polymorphic you can try to derive IMIDraw from IPlot2D, this way you can expose both interfaces and not violate the rule.
-
I design a COM object by ATL, which has two IDispath. Default dispatch is IPlot2D, and the second is IMIDraw. IMIDraw has a method Plot(), how do I launch Plot() method?
-
In addition to the previous reply, you can choose to implement your own IDispatch which will take care of all the methods for both interfaces. However, it is not the best solution, and you will have to take care to name clashes.
-
Thank you very much, solon. I put a new method Plot0() in IPlot2D, and Plot() is launch there. It's OK. Thanks again.