In this article I’ll explain the process of combining C++ and VBScript codes together. There are many situations in which you find yourself in desperate need of some simple code that can handle what your program wants to do. An example that comes to my mind is using DDE Protocol in Windows. It can be heartbreaking to try and write a quick DDE handling program using C++. Well on the other hand it is extremely easy using VBScript. But I am not going to talk about DDE I this post. Search Google for “how to connect to DDE using VBScript” and combine that with what you learn from this post. So here it is:
- 1. Add axcontainer to your used modules by adding the line below to your qmake project (.PRO file)
QT += axcontainer
- 2. Add ActiveQt to your include files
- 3. Create two variables in MainWindow for a QAxScriptManager and QAxScript
- 4. Initialize your QAxScript using QAxScriptManager. In this example it is assumed that the VBScript file is embedded as a resource but you can also use any VBScript file saved on disk.
main_scrpt = scrpt_mgr->load(“:/VBScript.vbs”, “MyScript”);
- 5. Call VBScript functions using the QAxScript class