Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In order to have multiple <code>IDispatch</code>-derived interfaces implemented on a single object, to be accessible from scripting environment you should rather implement <code>IDispatchEx</code> and have its methods called once a call from script is taking place. </p> <p>The problem you are facing is caused by the fact that script queries for your <code>IDispatch</code> first, and both your <code>IDispatch</code>-derived interfaces return the same "main" <code>IDispatch</code> leaving no chance for methods of other interfaces to be accessible.</p> <p>When VBS host is about to call a method on your object, it first queries <code>IDispatchEx</code>. If found, the calls are delivered via <code>IDispatchEx::InvokeEx</code> and your COM Class can internally route the call to the proper <code>IDispatch</code> implementation, both private or forward to external/inner object.</p> <p>In case <code>IDispatchEx</code> is not found, it looks for <code>IDispatch</code> and there you are in trouble because it sees only your "main" interface. That is, the workaround for you is to implement <code>IDispatchEx</code>. You can do it either way: implement right on your COM class, or instead create a proxy class to accept scripting calls via <code>IDispatchEx::InvokeEx</code> and forward to correct <code>IDispatch</code> in your code.</p> <p>Example: Both <code>A</code> and <code>B</code> classes implement <code>IX</code> and <code>IY</code> interfaces, <code>B</code> additionally implements <code>IDispatchEx</code>. Interface methods are <code>IX::X1</code>, <code>IY::Y1</code>.</p> <pre class="lang-vb prettyprint-override"><code>On Error Resume Next Set A = CreateObject("Test.A") WScript.Echo A.X1 ' Success, via IX::Invoke WScript.Echo A.Y1 ' Failure, A's IDispatch is IX's parent and does not have Y1 method Set B = CreateObject("Test.B") WScript.Echo B.X1 ' Success, via IDispatchEx::InvokeEx WScript.Echo B.Y1 ' Success, via IDispatchEx::InvokeEx </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload