The following illustration shows the interaction between an ActiveX Scripting host and an ActiveX Scripting engine.
Following is a description of the steps involved in the interaction between the host and engine (the actual nesting of the function calls is omitted for clarity):
- Create a Project. The host loads a project or document. (This step is not particular to ActiveX Scripting, but is included here for completeness.)
- Create the ActiveX Scripting Engine. The host calls CoCreateInstance to create a new ActiveX Scripting engine, specifying the class identifier (CLSID) of the specific scripting engine to use. For example, the HTML browsing component of Internet Explorer receives the scripting engine's class identifier through the CLSID= attribute of the HTML <OBJECT> tag.
- Load the Script. If the script contents have been persisted, the host calls the script engine's IPersist*::Load method to feed it the script storage, stream, or property bag. Otherwise, the host uses IPersist*::InitNew or IActiveScriptParse::InitNew to create a null script. A host that maintains a script as text can use IActiveScriptParse::ParseScriptText to feed the scripting engine the text of the script, after calling InitNew.
- Add Items. For each top-level named item (such as pages and forms) imported into the scripting engine's name space, the host calls IActiveScript::AddNamedItem to create an entry in the engine's name space. This step is not necessary if top-level named items are already part of the persistent state of the script loaded in step 3. A host does not use AddNamedItem to add sublevel named items (such as controls on an HTML page); rather, the engine indirectly obtains sublevel items from top-level items by using the host's ITypeInfo and IDispatch interfaces.
- Run the Script. The host causes the engine to start running the script by passing the SCRIPTSTATE_CONNECTED value to IActiveScript::SetScriptState. This call would likely perform any scripting engine construction work, including static bindings, hooking up to events (see below), and executing code similar to a scripted "main()" function.
- Get Item Information. Each time the script engine needs to associate a symbol with a top-level item, it calls the IActiveScriptSite::GetItemInfo method, which returns information about the given item.
- Hook Up Events. Before starting the actual script, the scripting engine connects to the events of all the relevant objects through the IConnectionPoint interface and other methods.
- Invoke Properties and Methods. As the script runs, the scripting engine realizes references to methods and properties on named objects through IDispatch::Invoke or other standard OLE binding mechanisms.
© 1996 Microsoft Corporation