Microsoft scriptcontrol User Guide

Source: Internet
Author: User

I. Preface
A lot of knowledge is always difficult to grasp, and you often have to search for information on the Internet.
Add some useful materials to your favorites and use them as a memo. This post is updated at any time.

Some of the materials come from the Internet. Thanks to the sharer, if they are similar and malicious, they are all learning.

--------------------------------------------------------------------------------

With the emergence of dynamic web pages, more and more people know, accept, and hold the script language. InProgramAdding support for scripts can expand the application scope to the maximum extent, and facilitate programmers to take advantage of some special functions (such as regular expressions) provided by existing scripts ).

Obviously, it is unrealistic to implement a script interpreter by yourself. Fortunately, there are reusable components, that is, Microsoft scriptcontrol. This is an ActiveX control, which is released along with Windows 2000. To use it in Windows earlier than Windows, you need to install this control (which can be found on the MS web site ).

Scriptcontrol Interface

attribute name
type
remarks
allowui
bool
checks whether user interface elements can be run. If it is false, interface elements such as message boxes are invisible.
codeobject
Object
the script is exposed to the object called by the host. Read-only.
modules
the Component Library module provided by the host to the script. Read-only. (COM components usually provide users with a collection of objects that can be left for secondary development. Each collection is a modules)
language
string
specifies or obtains the language interpreted by the script engine, such as VBScript and JScript.
name
string
name of the script engine. Read-only.
procedures
return the set of processes defined in the module
sitehwnd
hwnd
display the UI parent window handle in the script
state
Enum
set or return the control status, if the value is 0, the control only executes statements but does not forward events. If the value is 1, it is the object forwarding event accepted by the added control.
timeout
long
the timeout value of the control's script execution, -1 indicates no timeout.
usesafesubset
bool
sets or returns whether the host Program cares about security. The security level of the Host Program can be set from this attribute
error object. When an error occurs, this attribute returns an error object

Method Name
Parameters
Function
Addcode
Code as string
Add the script to be executed to the Script Engine
Addobject
Name as string, object as object, [addmembers as Boolean = false]
Add an object to the script engine so that the methods provided by the object can be used in the script.
Eval
Expression as string
Evaluate expressions
Executestatement
Statement as string
Interpret and execute script statements
Reset
Discard all objects andCode, Set the state attribute to 0.
Run
Procedurename as string, paramarray parameters () as Variant
Run a specified process

Event name
Function
Error
This event is triggered when an error occurs.
Timeout
Execution timeout occurs

General Usage
1. Add scriptcontrol to the program
2. Define a scriptcontrol instance
3. Call addcode to add the script to be executed to the script engine.
4. Call run to execute the script function.
Communication between hosts and scripts
1. Host call Script: This process is relatively simple. You only need to call run to pass the parameter to the script.

2. The script calls the host. during initialization, The addobject interface is called to expose one or more objects of the host to the script. In this case, the method of the Host object can be called in the script. In VC ++, this object is not a common C ++ class. It must support automation and can only call the automation interface in the object in the script (this is relatively simple in VB ).

Script debugging
Code written by anyone cannot be perfect at a time. However, the debugging methods vary depending on the specific execution location of the script. First, download a script debugger (I use Microsoft Script debugger, and the website has a download, and it is said that other tools such as VJ ++ can also be used). After installation, there is no start menu on the menu.
Debugger startup
In general advanced languages, you can easily set breakpoints. But how can I start debugging before I start the script debugger? When a script error occurs in IE, the system automatically prompts whether to debug the script. You can also add the interrupt code (VBScript: Stop javascript: debugger) to the script, but you still need to modify the Registry in scriptcontrol, change the value of jitdebug in HKEY_CURRENT_USER \ Software \ Microsoft \ Windows Script \ Settings to 1 (0 by default)
Example
The following is an example of easy language
. Version 2
. Subroutine
Coinitialize (0)
. Start to judge (script object. Create ("scriptcontrol ",))
. Default
Information Box ("unok", 0 ,)
. Judge the end
. Start to judge (script object. Write attribute ("language", "JavaScript "))
. Default
Information Box ("unok", 0 ,)
. Judge the end
Script object. Method ("addcode", # jsfunc)
Output debugging text (script object. Get error ())
Edit box T. Add text (script object. General Method ("run", "coo", "coofunction"). Take text (), # linefeed)
Output debugging text (script object. Get error ())
Couninitialize () to be resumed... called in the thread

Api_coinitialize ()
Api_couninitialize ()

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.