如何在C++中使用VBScript(使用Qt)--How to use VBScript in C++ (Using Qt)
来源:互联网 发布:数据多样性 ppt 编辑:程序博客网 时间:2024/04/30 03:48
原文链接:How to use VBScript in C++(Using Qt)
本文主要解释C++和VBScript脚本混编过程。存在多种使用简单代码以完成程序功能的情况。一个简单的例子的是在Windows下使用DDE通讯协议。想使用简单C++代码以完成该协议几乎让人崩溃。但是使用VBScript脚本是一件相当简单的事情。这里并不会讨论如何完成DDE通讯协议。使用Google搜索“如何使用VBScript链接DDE”并且结合本篇文章的学习。过程如下:
1.在qmake项目文件中添加axcontainer模块
QT+=axcontainer
2.包含ActiveQt头文
#include <ActiveQt>
3.在MainWindow中声明两个指针变量
QAxScriptManager *scrpt_mgr;QAxScript *main_scrpt;
4.使用QAxScriptManager初始化QAxScript指针变量。本例中,VBScript保存在Qt资源文件中,但是也可以将脚本文件放在磁盘任何地方
main_scrpt = scrpt_mgr->load(“:/VBScript.vbs”, “MyScript”);
5.使用QAxScript类调用VB脚本中函数
main_scrpt->call(“SaySomething(QString)”, “Hello!”);
源码下载链接:Download
===================================================================================================================================
XXNet项目在Windows下使用VBScript脚本完成运行工作,遇到没有生成桌面快捷方式的情况,start.vbs脚本如下:
Function CurrentPath() strPath = Wscript.ScriptFullName Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile(strPath) CurrentPath = objFSO.GetParentFolderName(objFile)End FunctionFunction CurrentVersion() strCurrentPath = CurrentPath() strVersionFile = strCurrentPath & "/code/version.txt" Set fso = CreateObject("Scripting.FileSystemObject") If (fso.FileExists(strVersionFile)) Then Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(strVersionFile,1) CurrentVersion = objFileToRead.ReadLine() version_path = strCurrentPath & "/code/" & CurrentVersion & "/launcher/start.py" If( Not fso.FileExists(version_path) ) Then CurrentVersion = "default" End If objFileToRead.Close Set objFileToRead = Nothing Else CurrentVersion = "default" End IfEnd FunctionFunction isConsole() Set objArgs = Wscript.Arguments 'WScript.Echo objArgs.Count 'WScript.Echo objArgs(0) isConsole = 0 If objArgs.Count > 0 Then if objArgs(0) = "console" Then isConsole = 1 End If End IfEnd FunctionstrCurrentPath = CurrentPath()strVersion = CurrentVersion()Dim strArgsquo = """"If isConsole() Then python_cmd = "python.exe"Else python_cmd = "pythonw.exe"End IfstrExecutable = quo & strCurrentPath & "\code\" & strVersion & "\python27\1.0\" & python_cmd & quostrArgs = strExecutable & " " & quo & strCurrentPath & "\code\" & strVersion & "\launcher\start.py" & quo'WScript.Echo strArgsSet oShell = CreateObject ("Wscript.Shell")oShell.Run strArgs, isConsole(), false
分析:
1.CurrentPath函数是返回当前目录路径
2.CurrentVersion是位于code目录下中version.txt中的版本信息
3.isConsole没有弄明白是啥,好像是使用控制台还是什么的运行python脚本
4.oShell通过获取的一系列参数运行xxnet
总之,弄了一下午并没有实质性的成果,并不可以在win平台下的cmd中直接敲指令就运行,但是发现想要运行VBScript,QAxScriptManager、QAxScript需要和QWidget一起使用。
继续折腾呢?
- 如何在C++中使用VBScript(使用Qt)--How to use VBScript in C++ (Using Qt)
- 如何在QT for S60 中使用pthread库(Carbide.c++) (How to use pthread in QT4.6 for S60)
- 在VBScript中使用类(一)
- 在VBScript中使用类(二)
- 在VBScript中使用类(三)
- 在VBScript中使用类(四)
- 在VBScript中使用类
- 在VBScript中使用类
- 在VBScript中使用类
- How to use ComboBox Control in VC++ - 在VC中如何使用 ComboBox 控件
- 如何在python中使用*args,**kwargs (How to use *args and **kwargs in Python)
- How to use bitBucket with EGit in Eclipse,如何在Eclipse中使用bitbucket远程仓库
- 如何使用VBScript
- 在VBScript中,像C一样使用include一个.vbs脚本
- 在iPhone应用中如何使用随机数(How to Use Random Numbers in Your iPhone App)
- how to use a foreach in Qt
- 在VBA中使用JAVASCRIPT和VBSCRIPT
- How to use logrotate to manage log files in linux(如何在Linux中使用logrotate去管理日志文件)
- Spark安装
- CSS选择框、下拉列表、文本域、表格
- Android动态权限问题
- halcon学习之图像相减算子sub_image
- 建立树状包结构
- 如何在C++中使用VBScript(使用Qt)--How to use VBScript in C++ (Using Qt)
- HDU1166 敌兵布阵
- 素数环
- 一文弄懂神经网络中的反向传播法——BackPropagation
- python学习笔记(2)
- EEPROM IIC
- 遍历集合时移除一个元素
- TCP三次握手和四次挥手
- OpenGL ES中的坐标变换