Let your programs execute scripts as well.

Source: Internet
Author: User
Tags wrapper

VBScript (JScript) is a scripting language that is widely used and easy to learn. It is easier to invoke a COM component using VBScript (JScript). Then, if you can execute the script in your program, it will greatly improve the function of the software on the basis of simplifying the program design. To facilitate the use of this feature, I wrote an EXE wrapper with an automated (Automation/idispatch) function to invoke script execution. This wrapper interface has only 2 functions, as described below:

Void setscriptlanguage (long nlanguage);

Features: Setting types that use scripting languages

Parameters: 0 = use vbscript 1 = use JScript

Note: If you do not call this function, the default is to use VBScript

Void Run (LPCSTR lpszprogram);

Functions: Executing scripts

Parameters: Scripting Programs

Use methods and steps: (The following instructions, is based on VC6, VC7 users please refer to the operation of changes)

Copy the file to any folder, and then execute the VBSENGIN.EXE program at least once. Complete the registration of the component.

Create or Open an MFC program project.

Add code to do COM initialization. Add a call to AfxOleInit () in the InitInstance () function of the app. or call function CoInitialize (NULL) before using COM functionality, and call CoUninitialize () after COM functionality finishes.

Add Vbsengin.tlb to the project. Open the ClassWizard dialog window and execute the from a type library of the Add Class button. Then select the Vbsengin.tlb file and add the wrapper class to the Ivbsengin interface.

In the appropriate place in your program (such as the Onbutton () function), complete the following code and execute the script.

#include "vbsengin.h"
OnButton()
{
  IVBSEngin vbsEngin;  //声明一个脚本执行代理对象
  if(vbsEngin.CreateDispatch("VBSEngin.Api")) //启动脚本执行代理
  {
    vbsEngin.Run(sProgram);  //执行脚本,sProgram中存放的是脚本源程序
    vbsEngin.ReleaseDispatch(); //释放脚本执行代理
  }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.