COM对象与添加的条目名称间的关联就是在IActiveScriptSite::GetItemInfo方法中进行的.
一旦这种关联被建立,你可以使用文档的方法与属性.如果你的应用中有一些方法返回接口到其它COM对象,你可以使用它们的方法与属性而不需要调用AddNamedItem.它们不是顶层对象,它们是由Document对象获得的(本例中只有一个对象-CAXSprite). 第三步:
Step 3
In this example we make our program able to fire some events which can be handled by the VBScript engine. First of all we will need to provide ITypeInfo information to the script engine. The application object has some members to hold this information (you can use global variables).
ITypeInfo* ptinfoClsDoc; //coclass Document ITypeInfo* ptinfoIntDoc; //dispinterface IAXHost ITypeInfo* ptinfoClsSprite; //coclass Sprite ITypeInfo* ptinfoIntSprite; //dispinterface IAXSpriteTo make your object fire events you need to create another interface to your object's events. Modify your ODL file.
Example:
In the CAXHostApp::InitInstance() method the type information was loaded
In the MainFrm.module:
The AddNamedItem was called with the SCRIPTITEM_ISSOURCE flag.
In the IActiveScriptSite::GetItemInfo ITypeInfo interface to the Document CLASS object has been provided to the scripting engine.
If you want your object support events, it must support IConnectionPointContainer interface and IProvideTypeInfo interface. See the article about CConnectionPoint MFC object. See how it was implemented with the CAXHostDoc object.
If you implement all the interfaces correctly, the scripting engine will establish a connection to your object and you will be able to fire events with help of a small function.
The iEvNum must be the same as in the ODL file. To fire the MouseDown event, for instance, i have to use iEvNum to be equal 1. Because [id(1)] void OnMouseDown([in] short x, [in] short y);
I should have made constants like IDEVENT_MOUSEDOWN and use them both in the ODL file and in my C++ code.
Example:
Observe the sequence of passing parameters to the variant array.
I am not sure that in this small description i have written all the tips to make your program work, but i send you the code which you can investigate. And you should alse see the "Axscript" example which does a little bit more. It provides a way how to make subclassing with VBScript. See the BuildTypeInfo function in the example to see how it has been done there.
If you have any questions, you can send me a message and i will try to answer. But i must confess that i am a novice in COM. COM is not difficult to understand but there are so many different objects and interfaces. And one must know how to use them in one's programs. The same can be said about the C++ language itself.
I also would like to get some examples on this matter if you have them. For example, i don't know how to implement debugging features (they say that Microsoft has already made a debugger fo VBScript), how to interrupt a running script (i think i should create an another thread and use an appropriate function), i tried to implement DUAL interfaces to my objects but the VBScript used just the IDispatch interfaces and i thought that VBScript did not support DUAL interfaces.
If you have any clues concerning this technology, please send them to me. I would like also your opinion whether this feature is interesting, for i can send some more examples. I mean not this sprites but a way of using this technology in business applications. For example, my program use special kinds of objects to work with SQL server databases and Access databases such as "recordsets", "idsets, "caches", "reports", "views" and others.