How to load & call a VBScript function from within C++?

后端 未结 2 1664
时光取名叫无心
时光取名叫无心 2020-12-03 12:34

We have customers asking for VBScript functions to be called when particular actions occur within our product. I\'ve been trying to research the Windows Scripting technologi

2条回答
  •  独厮守ぢ
    2020-12-03 12:55

    IActiveScript and related interfaces work very well. I use them in my product exactly the same way you have described. Some of out customers write their own VBScript and JScript scripts to analyze and update application data before it gets posted to a database.

    You use CoCreateInstance() to instantiate IActiveScript, like you would any other COM object. You would then call its QueryInterface() method to obtain an IActiveScriptParse interface for loading snippets of scripting code, and then you update the IActiveScript's state to execute the code.

    You can add custom objects to the script by implementing IDispatch-derived classes and then passing them to the engine using IActiveScript::AddNamedItem() and an IActiveScriptSite::GetItemInfo() callback.

    There are examples of IActiveScript usage available on MSDN.

提交回复
热议问题