winscript.lsp

Module index

source

Module: winscript

Embedded VBScript/JScript in newLISP.

Version: 0.21
Author: m35

Location: http://www.autohotkey.net/~easycom/winscript.lsp

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.

Tested with newlisp 9.2.0.

Contact me (m35) in the newLISP Fan Club forum http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1983

A good list of automation error descriptions can be found in KB186063

example:
 > (WINSCRIPT:Initialize)
 true
 > (WINSCRIPT:Exec {foo = "bar"})
 true
 > (WINSCRIPT:Eval {foo})
 "bar"
 > (WINSCRIPT:Uninitialize)
 true

example:
 > (WINSCRIPT:Initialize "VBScript")
 true
 > (WINSCRIPT:Exec {Set oSp = CreateObject("SAPI.SpVoice")})
 true
 > (WINSCRIPT:Exec {oSp.Speak "newLISP: Puts the fun back in LISP"})
 true

example:
 ; 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

Sets up the scripting environment. Must be called before any other functions can be used.

- § -

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.

- § -

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 last operation threw and 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