Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can turn your VBScript function into <code>IDispatch*</code> pointers. For example the <code>onreadystatechange</code> handler in the <code>Microsoft.XMLHTTP</code> object.</p> <pre><code>Option Explicit Dim xmlhttp Function OnReadyStateChange WScript.Echo "ReadyState: " &amp; xmlhttp.readyState End Function Set xmlhttp = CreateObject("Microsoft.XMLHTTP") xmlhttp.onreadystatechange = GetRef("OnReadyStateChange") xmlhttp.open "GET", "http://stackoverflow.com", True xmlhttp.send WScript.Echo "Waiting for 20 seconds to allow OnReadyStateChange events to finish." WScript.Sleep 20000 WScript.Echo "Done!" </code></pre> <p>Outputs:</p> <pre><code>ReadyState: 1 Waiting for 20 seconds to allow OnReadyStateChange events to finish. ReadyState: 2 ReadyState: 3 ReadyState: 4 Done! </code></pre> <p>Extracting the IDL for <code>C:\Windows\System32\msxml3.dll</code> shows we're setting an <code>IDispatch*</code> property:</p> <pre><code>[ odl, uuid(ED8C108D-4349-11D2-91A4-00C04F7969E8), helpstring("IXMLHTTPRequest Interface"), dual, oleautomation ] interface IXMLHTTPRequest : IDispatch { // ... [id(0x0000000e), propput, helpstring("Register a complete event handler")] HRESULT onreadystatechange([in] IDispatch* rhs); }; </code></pre> <p>When adapting this approach to your C++ application, your calling code will need to use <code>IDispatch::Invoke</code> with a DISPID of <code>DISPID_VALUE</code>, for example:</p> <pre><code>// IDispatch* pOnReadyStateChange &lt;-- set from VBScript. HRESULT hr = S_OK; CComVariant vResult; EXCEPINFO ei = { }; DISPPARAMS dispParams = { NULL, 0, 0, 0 }; hr = pOnReadyStateChange-&gt;Invoke( DISPID_VALUE, IID_NULL, 0, DISPATCH_METHOD, &amp;dispParams, &amp;vResult, &amp;ei, NULL); </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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