Initial commit of newLISP.
[newlisp.git] / modules / winscript.lsp.html
blob97044ccb12fa8abd065eb9aa7d37a712e07b39a4
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <META http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title>winscript.lsp</title>
7 <style type="text/css" media="screen">
8 <!--
9 span.arw {
10 color:#666666;
11 font-size: 100%;
14 body, p {
15 font-family: Georgia, Times New Roman, Times, serif;
16 line-height: 115%;
19 h1, h2, h3, h4 {
20 font-family: Georgia, Times New Roman, Times, serif;
21 font-size: 110%;
24 pre {
25 font-family: Andale Mono, "Bitstream Vera Sans Mono", Monaco, "Courier New";
26 font-size: 100%;
29 tt {
30 font-family: Andale Mono, "Bitstream Vera Sans Mono", Monaco, "Courier New";
31 font-size: 100%;
33 -->
34 </style>
35 </head>
37 <body style="margin: 20px;" text="#333333" bgcolor="#FFFFFF"
38 link="#376590" vlink="#551A8B" alink="#ffAA28">
39 <blockquote>
40 <center><h1>winscript.lsp</h1></center>
41 <p><a href="index.html">Module index</a></p><br/><br/><br/><h2>Module:&nbsp;winscript</h2><p>Embedded VBScript/JScript in newLISP.</p>
42 <b>Version: </b>0.21<br/>
43 <b>Author: </b>m35<br/>
44 <p></p>
45 <b>Location: </b><a href="http://www.autohotkey.net/~easycom/winscript.lsp">http://www.autohotkey.net/~easycom/winscript.lsp</a><br/>
46 <p></p>
47 Change log:
48 <p></p>
49 0.10 - Initial release.
50 <p></p>
51 0.11 - Fixed memory leak when unhandled type is returned.
52 Improved get-short and get-single functions.
53 <p></p>
54 0.12 - Fixed handling of automation errors.
55 <p></p>
56 0.20 - Large internal changes to properly handle errors. This fixes
57 memory leaks and provides more comprehensive error information.
58 Added <tt>(WINSCRIPT:LastResult)</tt> function to return the results of
59 win32api calls.
60 <p></p>
61 0.21 - Added missing cleanup if failure during initialization.
62 <p></p>
63 Tested with newlisp 9.2.0.
64 <p></p>
65 Contact me (m35) in the newLISP Fan Club forum
66 <a href="http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1983
67 ">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1983</a> <p></p>
68 A good list of automation error descriptions can be found in
69 <a href="http://support.microsoft.com/kb/186063">KB186063</a>
70 <p></p><b>example:</b><blockquote><pre> &gt; (WINSCRIPT:Initialize)
71 true
72 &gt; (WINSCRIPT:Exec {foo = "bar"})
73 true
74 &gt; (WINSCRIPT:Eval {foo})
75 "bar"
76 &gt; (WINSCRIPT:Uninitialize)
77 true</pre></blockquote>
78 <p></p><b>example:</b><blockquote><pre> &gt; (WINSCRIPT:Initialize "VBScript")
79 true
80 &gt; (WINSCRIPT:Exec {Set oSp = CreateObject("SAPI.SpVoice")})
81 true
82 &gt; (WINSCRIPT:Exec {oSp.Speak "newLISP: Puts the fun back in LISP"})
83 true</pre></blockquote>
84 <p></p><b>example:</b><blockquote><pre> ; this example requires Microsoft Excel to be installed.
85 &gt; (WINSCRIPT:Initialize)
86 true
87 &gt; (WINSCRIPT:Exec {Set xl = CreateObject("Excel.Application")})
88 true
89 &gt; (WINSCRIPT:Exec {xl.Visible = True})
90 true
91 &gt; (WINSCRIPT:Exec {Set rng = xl.Workbooks.Add().Worksheets(1).Cells(1, 1)})
92 true
93 &gt; (WINSCRIPT:Exec {rng.Value = 1.2345})
94 true
95 &gt; (WINSCRIPT:Eval {rng.Value})
96 1.2345
97 &gt; (WINSCRIPT:Exec {xl.DisplayAlerts = False})
98 true
99 &gt; (WINSCRIPT:Exec {xl.Quit})
100 true
101 &gt; (WINSCRIPT:Uninitialize)
102 true</pre></blockquote>
103 <p></p><center>- &sect; -</center><p></p>
104 <a name="WINSCRIPT_Initialize"></a><h3><font color=#CC0000>WINSCRIPT:Initialize</font></h3>
105 <b>syntax: (<font color=#CC0000>WINSCRIPT:Initialize</font> [<em>str-language</em>="VBScript"])</b><br/>
106 <b>parameter: </b><em>str-language</em> - either <tt>"VBScript"</tt> or <tt>"JScript"</tt><br/>
107 <p><b>return: </b>true on success, <tt>(throw-error)</tt> on error</p>
108 Sets up the scripting environment. Must be called before any other
109 functions can be used.
122 <p></p><center>- &sect; -</center><p></p>
123 <a name="WINSCRIPT_Uninitialize"></a><h3><font color=#CC0000>WINSCRIPT:Uninitialize</font></h3>
124 <b>syntax: (<font color=#CC0000>WINSCRIPT:Uninitialize</font>)</b><br/>
125 <p><b>return: </b><tt>true</tt></p>
126 Releases memory for scripting environment. Does not have to be called before
127 exiting the program, but it is good practice.
133 <p></p><center>- &sect; -</center><p></p>
134 <a name="WINSCRIPT_Exec"></a><h3><font color=#CC0000>WINSCRIPT:Exec</font></h3>
135 <b>syntax: (<font color=#CC0000>WINSCRIPT:Exec</font> <em>str-code</em>)</b><br/>
136 <b>parameter: </b><em>str-code</em> - code to execute<br/>
137 <p><b>return: </b><tt>true</tt> on success, <tt>(throw-error)</tt> on error.</p>
138 Executes the scripting code.
143 <p></p><center>- &sect; -</center><p></p>
144 <a name="WINSCRIPT_Eval"></a><h3><font color=#CC0000>WINSCRIPT:Eval</font></h3>
145 <b>syntax: (<font color=#CC0000>WINSCRIPT:Eval</font> <em>str-code</em>)</b><br/>
146 <b>parameter: </b><em>str-code</em> - code to evaluate<br/>
147 <p><b>return: </b>resulting value on success, <tt>(throw-error)</tt> on error.</p>
148 Evaluates the scripting code and returns the result. Returned types can be
149 String, Byte, Integer, Long, Float, Double, Boolean (<tt>true</tt> or <tt>nil</tt>),
150 or object pointer. Uninitialized variables ("Empty") are returned as an
151 empty list. The remaining types (Arrays, Currency, Date, VARIANT*, and
152 DECIMAL*) are not handled and will cause an error if returned. Convert these
153 unhandled types to handled type (such as String) to return the value.
154 <p></p>
155 <p></p><b>example:</b><blockquote><pre> &gt; (WINSCRIPT:Initialize)
156 true
157 &gt; (WINSCRIPT:Eval "Now()")
158 user error : Unhandled variant type
159 called from user defined function WINSCRIPT:Eval
160 &gt; (WINSCRIPT:Eval "CStr(Now())")
161 "1/9/2008 10:07:10 PM"</pre></blockquote>
162 <p></p><center>- &sect; -</center><p></p>
163 <a name="WINSCRIPT_LastResult"></a><h3><font color=#CC0000>WINSCRIPT:LastResult</font></h3>
164 <b>syntax: (<font color=#CC0000>WINSCRIPT:LastResult</font>)</b><br/>
165 <p><b>return: </b>list of win32api function results during the last WINSCRIPT call.</p>
166 The returned list of strings will hold the results of all win32api functions
167 that could have failed during the last operation. If the last operation
168 threw and error, the last item in the list will be the error message
169 thrown.
170 <p></p>
171 <p></p><b>example:</b><blockquote><pre> &gt; (WINSCRIPT:Initialize)
172 true
173 &gt; (WINSCRIPT:Exec "#$@#$$^$&*&&")
174 user error : Expected statement
175 called from user defined function WINSCRIPT:Exec
176 &gt; (WINSCRIPT:LastResult)
177 ("MultiByteToWideChar ok" "SysAllocString ok"
178 "IScriptControl.ExecuteStatement -2146827264"
179 "IScriptError.Description 0" "WideCharToMultiByte ok" "Expected statement")</pre></blockquote>
181 <p></p><center>- &part; -</center><br/>
182 <center><font face='Arial' size='-2' color='#444444'>
183 generated with <a href="http://newlisp.org">newLISP</a>&nbsp;
184 and <a href="http://newlisp.org/newLISPdoc.html">newLISPdoc</a>
185 </font></center>
186 </blockquote>
187 </body>
188 </html>