source download winscript.lsp
Module: winscript
Embedded VBScript/JScript in newLISP.
Version: 0.23
Author: m35
Location: http://www.autohotkey.net/~easycom/winscript.lsp
http://www.autohotkey.net/~easycom/winscript.lsp This module uses the COM/OLE Microsoft Scripting Control object to execute VBScript or JScript. Most computers have it installed by default. It can also be downloaded directly from Microsoft.
http://www.microsoft.com/downloads/details.aspx?FamilyId=D7E31492-2595-49E6-8C02-1426FEC693AC
Change log:
0.10 - Initial release.
0.11 - Fixed memory leak when unhandled type is returned. Improved get-short and get-single functions.
0.12 - Fixed handling of automation errors.
0.20 - Large internal changes to properly handle errors. This fixes memory leaks and provides more comprehensive error information. Added (WINSCRIPT:LastResult) function to return the results of win32api calls.
0.21 - Added missing cleanup if failure during initialization.
0.22 - Minor documentation improvements. Added check at initialization if already initialized. Fixed error handling when the error doesn't come from the script control. Lots of internal cleaning and comments.
0.23 - changed import type constant 265 to 2312 as required since 10.4.0 , L.M.
Tested with newLISP 9.2.0 and 9.4.3.
Contact me (m35) in the newLISP Fan Club forum http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1983/a br/br/ A good list of automation error descriptions can be found in KB186063 Example:Example:> (WINSCRIPT:Initialize) true > (WINSCRIPT:Exec {foo = "bar"}) true > (WINSCRIPT:Eval {foo}) "bar" > (WINSCRIPT:Uninitialize) trueExample:> (WINSCRIPT:Initialize "VBScript") true > (WINSCRIPT:Exec {Set oSp = CreateObject("SAPI.SpVoice")}) true > (WINSCRIPT:Exec {oSp.Speak "newLISP: Puts the fun back in LISP"}) true; this example requires Microsoft Excel to be installed. > (WINSCRIPT:Initialize) true > (WINSCRIPT:Exec {Set xl = CreateObject("Excel.Application")}) true > (WINSCRIPT:Exec {xl.Visible = True}) true > (WINSCRIPT:Exec {Set rng = xl.Workbooks.Add().Worksheets(1).Cells(1, 1)}) true > (WINSCRIPT:Exec {rng.Value = 1.2345}) true > (WINSCRIPT:Eval {rng.Value}) 1.2345 > (WINSCRIPT:Exec {xl.DisplayAlerts = False}) true > (WINSCRIPT:Exec {xl.Quit}) true > (WINSCRIPT:Uninitialize) true§
WINSCRIPT:Initialize
syntax: (WINSCRIPT:Initialize [str-language="VBScript"])
parameter: str-language - either "VBScript" or "JScript"
return: true on success, (throw-error) on error
Initializes the scripting environment. Must be called before any other functions can be used.
If the scripting environment has already been initialized, this function does nothing.§
WINSCRIPT:Uninitialize
syntax: (WINSCRIPT:Uninitialize)
return: true
Releases memory for scripting environment. Does not have to be called before exiting the program, but it is good practice.
If the scripting environment is not initialized, this function does nothing.§
WINSCRIPT:Exec
syntax: (WINSCRIPT:Exec str-code)
parameter: str-code - code to execute
return: true on success, (throw-error) on error.
Executes the scripting code.§
WINSCRIPT:Eval
syntax: (WINSCRIPT:Eval str-code)
parameter: str-code - code to evaluate
return: resulting value on success, (throw-error) on error.
Evaluates the scripting code and returns the result. Returned types can be String, Byte, Integer, Long, Float, Double, Boolean (true or nil), or object pointer. Uninitialized variables ("Empty") are returned as an empty list. The remaining types (Arrays, Currency, Date, VARIANT*, and DECIMAL*) are not handled and will cause an error if returned. Convert these unhandled types to handled type (such as String) to return the value.
Example:> (WINSCRIPT:Initialize) true > (WINSCRIPT:Eval "Now()") user error : Unhandled variant type called from user defined function WINSCRIPT:Eval > (WINSCRIPT:Eval "CStr(Now())") "1/9/2008 10:07:10 PM"§
WINSCRIPT:LastResult
syntax: (WINSCRIPT:LastResult)
return: list of win32api function results during the last WINSCRIPT call.
The returned list of strings will hold the results of all win32api functions that could have failed during the last operation. If the most recent operation threw an error, the last item in the list will be the error message thrown.
Example:> (WINSCRIPT:Initialize) true > (WINSCRIPT:Exec "#$@#$$^$&*&&") user error : Expected statement called from user defined function WINSCRIPT:Exec > (WINSCRIPT:LastResult) ("MultiByteToWideChar ok" "SysAllocString ok" "IScriptControl.ExecuteStatement -2146827264" "IScriptError.Description 0" "WideCharToMultiByte ok" "Expected statement")- ∂ -
generated with newLISP and newLISPdoc