Debian Codegraph @

Contrib/System/System.html

raw
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <meta name="color-scheme" content="light dark">
7 <title>System Plug-in (NSIS)</title>
8 <style type="text/css">
9 :root { color-scheme: light dark; }
10 html, body { font-family: Verdana, Arial, Helvetica, sans-serif; color: #050505; background-color: #fefefe; }
11 html { font-size: 0.84em; }
12 body { font-size: 1em; font-size: 1rem; }
13 pre, code { font-family: Courier New, Courier, monospace,serif; font-size: 100%; }
14 h1 { font-size: 170%; }
15 h2 { font-size: 150%; }
16 h3 { font-size: 130%; }
17 h4 { font-size: 120%; }
18 h5 { font-size: 115%; }
19 h6 { font-size: 110%; }
20 blockquote { margin:0; padding:0; margin-left: 0.5em; }
21 blockquote pre { background-color: #fefefe; }
22
23 @media (prefers-color-scheme: dark) {
24 html, body { color: #eeeeee; background-color: #161616; }
25 blockquote pre { background-color: #202020; }
26 }
27 </style>
28 </head>
29 <body>
30 <h1>NSIS System Plug-in</h1>
31 <p>
32 <i>Copyright &copy; 2002 brainsucker (Nik Medved)</i><br><i>Copyright &copy; 2002-2026 NSIS Contributors</i>
33 </p>
34
35 <h2>Table of Contents</h2>
36
37 <ul>
38 <li><a href="#intro">Introduction</a></li>
39 <li>
40 <a href="#funcs">Available Functions</a>
41 <ul>
42 <li><a href="#memfuncs">Memory Related Functions</a></li>
43 <li><a href="#callfuncs">Calling Functions</a></li>
44 <li><a href="#64bitfuncs">64-bit Functions</a></li>
45 </ul>
46 </li>
47 <li><a href="#faq">FAQ</a></li>
48 </ul>
49
50 <h2><a name="intro"></a>Introduction</h2>
51
52 <p>The System plug-in gives developers the ability to call any exported function from any DLL. For example, you can use it to call <a href="https://msdn.microsoft.com/en-us/library/aa364975">GetLogicalDriveStrings</a> to get a list of available drives on the user's computer.</p>
53
54 <p>The System plug-in also allows the developer to allocate, free and copy memory; interact with COM objects and perform mathematical operations on 64-bit integers.</p>
55
56 <p>Programming knowledge is highly recommended for good understanding of the System plug-in.</p>
57
58 <h4>Usage Examples From The Wiki</h4>
59
60 <ul>
61 <li><a href="https://nsis.sourceforge.io/wiki/Get_Local_Time">Get local time</a></li>
62 <li><a href="https://nsis.sourceforge.io/wiki/Registering_a_Palm_Com_Conduit">Register conduits with Palm HotSync</a></li>
63 <li><a href="https://nsis.sourceforge.io/wiki/Determining_free_memory_using_the_System_plugin">Get free memory</a></li>
64 <li><a href="https://nsis.sourceforge.io/wiki/REG_MULTI_SZ_Reader">Read REG_MULTI_SZ</a></li>
65 <li><a href="https://nsis.sourceforge.io/wiki/Get_Disk_Volume_Serial_Number">Get disk serial number</a></li>
66 <li><i><a href="https://nsis.sourceforge.io/Special:Search?search=System%3A%3ACall">Search all...</a></i></li>
67 </ul>
68
69 <h2><a name="funcs"></a>Available Functions</h2>
70
71 <h3><a name="memfuncs"></a>Memory Related Functions</h3>
72
73 <div>
74 <ul>
75
76 <li>
77 <b>Alloc</b> <i>SIZE</i>
78 <blockquote>
79 <p>Allocates <i>SIZE</i> bytes and returns a memory address on the stack.</p>
80 <h4>Usage Example</h4>
81 <blockquote><pre>
82 System::<b>Alloc</b> 64
83 Pop $0
84 DetailPrint "64 bytes allocated at $0"
85 System::Free $0
86 </pre></blockquote>
87 </blockquote>
88 </li>
89 <li>
90 <b>StrAlloc</b> <i>SIZE</i>
91 <blockquote>
92 <p>Allocates a string buffer for <i>SIZE</i> <b>TCHARs</b> and returns a memory address on the stack. This is extremely useful if you want to write an NSI script that will work for both ANSI and Unicode NSIS.</p>
93 <h4>Usage Example</h4>
94 <blockquote><pre>
95 System::<b>StrAlloc</b> 64 ; String buffer for 63 characters and \0 termination.
96 Pop $0
97 DetailPrint "A string buffer for 64 characters allocated at $0"
98 System::Free $0
99 </pre></blockquote>
100 </blockquote>
101 </li>
102 <li>
103 <b>Copy</b> [/<i>SIZE</i>] <i>DESTINATION</i> <i>SOURCE</i>
104 <blockquote>
105 <p>Copies <i>SIZE</i> bytes from <i>SOURCE</i> to <i>DESTINATION</i>. If <i>SIZE</i> is not specified, <i>SOURCE</i>'s size will queried using GlobalSize. This means that if you don't allocate <i>SOURCE</i> using System::Alloc, System::Call or GlobalAlloc, you must specify <i>SIZE</i>. If <i>DESTINATION</i> is zero it will be allocated and its address will be pushed on the stack.</p>
106 <h4>Usage example</h4>
107 <blockquote><pre>
108 # allocate a buffer and put 'test string' and an int in it
109 System::Call "*(&amp;t1024 'test string', i 5) p .s"
110 Pop $0
111 # copy to an automatically created buffer
112 System::<b>Copy</b> 0 $0
113 Pop $1
114 # get string and int in $1 buffer
115 System::Call "*$1(&amp;t1024 .r2, i .r3)"
116 # free buffer
117 System::Free $1
118 # print result
119 DetailPrint $2
120 DetailPrint $3
121 # copy to our own buffer
122 System::Alloc 1028
123 Pop $1
124 System::<b>Copy</b> $1 $0
125 # get string and int in $1 buffer
126 System::Call "*$1(&amp;t1024 .r2, i .r3)"
127 # free
128 System::Free $0
129 System::Free $1
130 # print result
131 DetailPrint $2
132 DetailPrint $3
133 </pre></blockquote>
134 </blockquote>
135
136 </li>
137
138 <li>
139 <b>Free</b> <i>ADDRESS</i>
140 <blockquote>
141 <p>Frees <i>ADDRESS</i>.</p>
142 <h4>Usage Example</h4>
143 <blockquote><pre>
144 System::Alloc 64
145 Pop $0
146 DetailPrint "64 bytes allocated at $0"
147 System::<b>Free</b> $0
148 </pre></blockquote>
149 </blockquote>
150 </li>
151
152 <li>
153 <b>Store</b> "<i>OPERATION</i> [<i>OPERATION</i> [<i>OPERATION</i> ...]]"
154 <blockquote>
155 <p>Performs stack operations. An operation can be pushing or popping a single register from the NSIS stack or pushing or popping all of the registers ($0-$9 and $R0-$R9) from System's private stack. Operations can be separated by any character.</p>
156 <h4>Available Operations</h4>
157 <ul>
158 <li>To push $<i>#</i>, use p<i>#</i>, where <i>#</i> is a digit from 0 to 9.</li>
159 <li>To pop $<i>#</i>, use r<i>#</i>, where <i>#</i> is a digit from 0 to 9.</li>
160 <li>To push $R<i>#</i>, use P<i>#</i>, where <i>#</i> is a digit from 0 to 9.</li>
161 <li>To pop $R<i>#</i>, use R<i>#</i>, where <i>#</i> is a digit from 0 to 9.</li>
162 <li>To push $0-$9 and $R0-$R9 to System's private stack, use s or S.</li>
163 <li>To pop $0-$9 and $R0-$R9 from System's private stack, use l or L.</li>
164 <li>To push the internal NSIS flags state <small>(exec_flags_t in api.h)</small> to the stack, use F.</li>
165 <li>To pop the internal NSIS flags state <small>(exec_flags_t in api.h)</small> from the stack, use f.</li>
166 </ul>
167 <h4>Usage Examples</h4>
168 <blockquote><pre>
169 StrCpy $0 "test"
170 System::<b>Store</b> "p0"
171 Pop $1
172 DetailPrint "$0 = $1"
173 </pre></blockquote>
174 <blockquote><pre>
175 StrCpy $2 "test"
176 System::<b>Store</b> "p2 R2"
177 DetailPrint "$2 = $R2"
178 </pre></blockquote>
179 <blockquote><pre>
180 StrCpy $3 "test"
181 System::<b>Store</b> "s"
182 StrCpy $3 "another test"
183 System::<b>Store</b> "l"
184 DetailPrint $3
185 </pre></blockquote>
186 <blockquote><pre>
187 System::<b>Store</b> "r4" "test"
188 DetailPrint $4
189 </pre></blockquote>
190 </blockquote>
191 </li>
192 </ul>
193
194 </div>
195
196 <h3><a name="callfuncs"></a>Calling Functions</h3>
197
198 <div>
199
200 <ul>
201 <li><b>Call</b> <i>PROC</i> [( <i>PARAMS</i> ) [<i>RETURN</i> [? <i>OPTIONS</i>]]]</li>
202 <li><b>Get</b> <i>PROC</i> [( <i>PARAMS</i> ) [<i>RETURN</i> [? <i>OPTIONS</i>]]]
203 <blockquote>
204 <p>Call and get both share a common syntax. As the names suggest, Call calls and Get gets. What does it call or get? It depends on <i>PROC</i>'s value.</p>
205
206 <p><i>PARAMS</i> is a list of parameters and what do to with them. You can pass data in the parameters and you can also get data from them. The parameters list is separated by commas. Each parameter is combined of three values: <i>type</i>, <i>source</i> and <i>destination</i>. <i>Type</i> can be an integer, a string, etc. <i>Source</i>, which is the source of the parameter value, can be a NSIS register ($0, $1, $INSTDIR), the NSIS stack, a concrete value (5, "test", etc.) or nothing (null). <i>Destination</i>, which is the destination of the parameter value after the call returns, can be a NSIS register, the NSIS stack or nothing which means no output is required. Either one of <i>source</i> or <i>destination</i> can also be a dot (`.') if it is not needed.</p>
207
208 <p><i>RETURN</i> is like a single parameter definition, but <i>source</i> is only used when creating callback functions. Normally <i>source</i> is a dot.</p>
209
210 <p><i>OPTIONS</i> is a list of options which control the way System plug-in behaves. Each option can be turned off by prefixing with an exclamation mark. For example: <b>?!e</b>.</p>
211
212 <p><i>PARAMS</i>, <i>RETURN</i> and <i>OPTIONS</i> can be repeated many times in one Get/Call line. When repeating, a lot can be omitted, and only what you wish to change can be used. <i>Type</i>, <i>source</i> and/or <i>destination</i> can be omitted for each parameter, even the return value. Options can be added or removed. This allows you to define function prototypes and save on some typing. The <a href="#repeat">last two examples</a> show this.</p>
213
214 <p><i>PROC</i> can also be <a href="#repeatproc">repeated</a> but it must be prefixed with a hash sign (`#') except if the hash sign is preceded by a double colon (<code>shell32::#18</code>) in which case it is interpreted as a function ordinal.</p>
215
216 <h4>Possible <i>PROC</i> Values and Meanings</h4>
217
218 <blockquote>
219 <table>
220 <tr>
221 <th>Value</th>
222 <th>Meaning</th>
223 <th>Example</th>
224 </tr>
225 <tr>
226 <th><i>DLL</i>::<i>FUNC</i></th>
227 <td><i>FUNC</i> exported from <i>DLL</i></td>
228 <td><a href="#func">user32::MessageBox</a></td>
229 </tr>
230 <tr>
231 <th>::<i>ADDR</i></th>
232 <td>Function located at <i>ADDR</i></td>
233 <td><a href="#funcaddr">see below</a></td>
234 </tr>
235 <tr>
236 <th>*<i>ADDR</i></th>
237 <td>Structure located at <i>ADDR</i></td>
238 <td><a href="#structaddr">see below</a></td>
239 </tr>
240 <tr>
241 <th>*</th>
242 <td>New structure</td>
243 <td><a href="#newstruct">see below</a></td>
244 </tr>
245 <tr>
246 <th><i>IPTR</i>-><i>IDX</i></th>
247 <td>Member indexed <i>IDX</i> from<br>interface pointed by <i>IPTR</i></td>
248 <td><a href="#com">see below</a></td>
249 </tr>
250 <tr>
251 <th>&lt;nothing&gt;</th>
252 <td>New callback function</td>
253 <td><a href="#callback">see below</a></td>
254 </tr>
255 <tr>
256 <th><i>PROC</i></th>
257 <td><i>PROC</i> returned by Get</td>
258 <td><a href="#get">see below</a></td>
259 </tr>
260 </table>
261 </blockquote>
262
263 <h4>Available Parameter Types</h4>
264
265 <blockquote>
266 <table>
267 <tr>
268 <th>Type</th>
269 <th>Meaning</th>
270 </tr>
271 <tr>
272 <th>v</th>
273 <td>void (generally for return)</td>
274 <td></td>
275 </tr>
276 <tr>
277 <th>p</th>
278 <td>pointer (and other pointer sized types like handles and HWNDs)</td>
279 </tr>
280 <tr>
281 <th>b</th>
282 <td>int8, byte</td>
283 </tr>
284 <tr>
285 <th>h</th>
286 <td>int16, short</td>
287 </tr>
288 <tr>
289 <th>i</th>
290 <td>int32 (includes char, byte, short and so on when used as a pointer)</td>
291 </tr>
292 <tr>
293 <th>l</th>
294 <td>int64, large integer</td>
295 </tr>
296 <tr>
297 <th>m</th>
298 <td>ANSI text, string. (FYI: 'm' for multibyte string or 'w' flipped over.)</td>
299 </tr>
300 <tr>
301 <th>t</th>
302 <td>text, string (pointer to first character). <i>Like TCHAR*, it is a Unicode string in Unicode NSIS.</i></td>
303 </tr>
304 <tr>
305 <th>w</th>
306 <td>WCHAR text, Unicode string</td>
307 </tr>
308 <tr>
309 <th>g</th>
310 <td>GUID</td>
311 </tr>
312 <tr>
313 <th>k</th>
314 <td>callback</td>
315 </tr>
316 <tr>
317 <th>@</th>
318 <td>Direct register memory access (Buffer is limited to <code>(NSIS_MAX_STRLEN - 24) * NSIS_CHAR_SIZE</code> bytes)</td>
319 </tr>
320 <tr>
321 <th>&amp;v<i>N</i></th>
322 <td><i>N</i> bytes padding (structures only)</td>
323 </tr>
324 <tr>
325 <th>&amp;i<i>N</i></th>
326 <td>integer of <i>N</i> bytes (structures only)</td>
327 </tr>
328 <tr>
329 <th>&amp;l</th>
330 <td>structure size (structures only)</td>
331 </tr>
332 <tr>
333 <th>&amp;t<i>N</i></th>
334 <td>array of <i>N</i> TCHAR text characters (structures only)</td>
335 </tr>
336 <tr>
337 <th>&amp;m<i>N</i></th>
338 <td>array of <i>N</i> CHAR ANSI characters (structures only)</td>
339 </tr>
340 <tr>
341 <th>&amp;w<i>N</i></th>
342 <td>array of <i>N</i> WCHAR Unicode characters (structures only)</td>
343 </tr>
344 <tr>
345 <th>&amp;g<i>16</i></th>
346 <td><i>16</i> bytes of GUID (structures only)</td>
347 </tr>
348 </table>
349 <p>Additionally, each type (except <i>b</i>, <i>h</i>, <i>k</i> and <i>@</i>) can be prefixed with an asterisk to denote a pointer. When using an asterisk, the System plug-in still expects the value of the parameter, rather than the pointer's address. To pass a direct address, use `p' with no asterisk. A <a href="#pointer">usage example</a> is available. <a href="#memfuncs">Alloc</a> returns addresses and its return value should therefore be used with `p', without an asterisk.</p>
350 </blockquote>
351
352 <h4>Available Sources and Destinations</h4>
353
354 <blockquote>
355 <table>
356 <tr>
357 <th>Type</th>
358 <th>Meaning</th>
359 </tr>
360 <tr>
361 <th>.</th>
362 <td>ignored</td>
363 <td></td>
364 </tr>
365 <tr>
366 <th><i>number</i></th>
367 <td>concrete hex, decimal or octal integer value. several integers can be or'ed using the pipe symbol (`|')</td>
368 </tr>
369 <tr>
370 <th>'<i>string</i>'<br>"<i>string</i>"<br>`<i>string</i>`</th>
371 <td>concrete string value</td>
372 </tr>
373 <tr>
374 <th><i>r0</i> through <i>r9</i></th>
375 <td>$0 through $9 respectively</td>
376 </tr>
377 <tr>
378 <th><i>r10</i> through <i>r19</i><br><i>R0</i> through <i>R9</i></th>
379 <td>$R0 through $R9 respectively</td>
380 </tr>
381 <tr>
382 <th>c</th>
383 <td>$CMDLINE</td>
384 </tr>
385 <tr>
386 <th>d</th>
387 <td>$INSTDIR</td>
388 </tr>
389 <tr>
390 <th>o</th>
391 <td>$OUTDIR</td>
392 </tr>
393 <tr>
394 <th>e</th>
395 <td>$EXEDIR</td>
396 </tr>
397 <tr>
398 <th>a</th>
399 <td>$LANGUAGE</td>
400 </tr>
401 <tr>
402 <th>s</th>
403 <td>NSIS stack</td>
404 </tr>
405 <tr>
406 <th>n</th>
407 <td>null for source, no output required for destination</td>
408 </tr>
409 </table>
410 <p>Source is required when using the @ type and must be a register. When the call returns the source register already contains the memory address in string form so using destination is usually <a href="#directvarmemparam">not necessary</a>.
411 </blockquote>
412
413 <h4>Callbacks</h4>
414
415 <blockquote>
416 <p>Callback functions are simply functions which are passed to a function and called back by it. They are frequently used to pass a possibly large set of data item by item. For example, <a href="https://msdn.microsoft.com/en-us/library/ms633494">EnumChildWindows</a> uses a <a href="https://msdn.microsoft.com/en-us/library/ms633493">callback function</a>. As NSIS functions are not quite regular functions, the System plug-in provides its own mechanism to support callback functions. It allows you to create callback functions and notifies you each time a callback function was called.</p>
417
418 <p>Creation of callback functions is done using <a href="#callfuncs">Get</a> and the callback creation syntax. As you will not call the callbacks yourself, the source of the parameters should be omitted using a dot. When the callback is called, the destination of the parameters will be filled with the values passed on to the callback. The value the callback will return is set by the source of the return "parameter". The destination of the return "parameter" should always be set as that's where System will notify you the callback was called.</p>
419
420 <blockquote><pre>System::Get "(i .r0, i .r1) iss"</pre></blockquote>
421
422 <p>To pass a callback to a function, use the k type.</p>
423
424 <blockquote><pre>System::Get "(i .r0, i .r1) isR0"
425 Pop $0
426 System::Call "dll::UseCallback(k r0)"</pre></blockquote>
427
428 <p>Each time the callback is called, the string callback#, where # is the number of the callback, will be placed in the destination of the return "parameter". The number of the first callback created is 1, the second's is 2, the third's is 3 and so on. As System is single threaded, a callback can only be called while calling another function. For example, EnumChildWindows's callback can only be called when EnumChildWindows is being called. You should therefore check for callback# after each function call that might call your callback.</p>
429
430 <blockquote><pre>System::Get "(i .r0, i .r1) isR0"
431 Pop $0
432 System::Call "dll::UseCallback(k r0)"
433 StrCmp $R0 "callback1" 0 +2
434 DetailPrint "UseCallback passed ($0, $1) to the callback"
435 </pre></blockquote>
436
437 <p>After you've processed the callback call, you should use <a href="#callfuncs">Call</a>, passing it the value returned by <a href="#callfuncs">Get</a> - the callback. This tells System to return from the callback. Destination of the return "parameter" must be cleared prior to calling a function, to avoid false detection of a callback call. If you've specified a source for the return "parameter" when the callback was created, you should fill that source with the appropriate return value. Callbacks are not automatically freed, don't forget to free it after you've finished using it.</p>
438
439 <blockquote><pre>System::Get "(i .r0, i .r1) isR0"
440 Pop $0
441 System::Call "dll::UseCallback(k r0)"
442 loop:
443 StrCmp $R0 "callback1" 0 done
444 DetailPrint "UseCallback passed ($0, $1) to the callback"
445 Push 1 # return value of the callback
446 StrCpy $R0 "" # clear $R0 in case there are no more callback calls
447 System::Call $0 # tell system to return from the callback
448 Goto loop
449 done:
450 System::Free $0
451 </pre></blockquote>
452
453 <p>A complete working <a href="#callback">example</a> is available in the usage examples section.</p>
454
455 </blockquote>
456
457 <h4>Notes</h4>
458
459 <blockquote>
460 <ul>
461 <li>To find out the index of a member in a COM interface, you need to search for the definition of this COM interface in the header files that come with Visual C/C++ or the Platform SDK. The index is zero based.</li>
462 <li>If a function can't be found or the <code>t</code> parameter type was used, an `A' or `W' will be appended to its name and it will be looked up again. This is done because a lot of Windows API functions have two versions, one for ANSI strings and one for Unicode strings. The ANSI version of the function is marked with `A' and the Unicode version is marked with `W'. For example: lstrcpyA and lstrcpyW.</li>
463 <li>Libraries in the system32 directory can be loaded without a path. All other libraries should be loaded with a <a href="#funcqpath">quoted full path</a>.</li>
464 </ul>
465 </blockquote>
466
467 <h4>Available Options</h4>
468
469 <blockquote>
470 <table>
471 <tr>
472 <th>Option</th>
473 <th>Meaning</th>
474 </tr>
475 <tr>
476 <th>c</th>
477 <td>cdecl calling convention (the stack restored by caller). By default stdcall calling convention is used on x86 (the stack restored by callee).</td>
478 <td></td>
479 </tr>
480 <tr>
481 <th>r</th>
482 <td>Always return (for GET means you should pop result and proc, for CALL means you should pop result (at least)). By default result is returned for errors only (for GET you will pop either error result or right proc, and for CALL you will get either your return or result at defined return place).</td>
483 </tr>
484 <tr>
485 <th>n</th>
486 <td>No redefine. Whenever this proc will be used it will never be redefined either by GET or CALL. This options is never inherited to children.</td>
487 </tr>
488 <tr>
489 <th>s</th>
490 <td>Use general Stack. Whenever the first callback defined the system starts using the temporary stacks for function calls.</td>
491 </tr>
492 <tr>
493 <th>e</th>
494 <td>Call GetLastError() after procedure end and push result on stack.</td>
495 </tr>
496 <tr>
497 <th>u</th>
498 <td>Unload DLL after call (using FreeLibrary, so you'll be able to delete it for example).</td>
499 </tr>
500 <tr>
501 <th>2</th>
502 <td>Experimental v2 syntax</td>
503 </tr>
504 </table>
505 </blockquote>
506
507 <h4>Experimental v2 syntax</h4>
508
509 <ul>
510 <li>Struct types in <a href="#v2typealign">uppercase are aligned</a> to their natural alignment. Lowercased types are packed without alignment.
511 <li><a href="#v2callback">Callback id</a> based on the allocated callback
512 </ul>
513
514 <h4>Usage Examples</h4>
515
516 <blockquote><pre>
517 <a name="func"></a>System::<b>Call</b> 'user32::MessageBox(p $HWNDPARENT, t "NSIS System Plug-in", t "Test", i 0)'
518 <a name="funcqpath"></a>System::<b>Call</b> '"$SysDir\MyLibrary.dll"::MyFunction(i 42)'
519 </pre></blockquote>
520 <blockquote><pre>
521 <a name="funcaddr"></a>System::<b>Call</b> "kernel32::GetModuleHandle(t 'user32.dll') p .s"
522 System::<b>Call</b> "kernel32::GetProcAddress(p s, m 'MessageBoxA') p .r0"
523 System::<b>Call</b> "::$0(p $HWNDPARENT, m 'GetProcAddress test', m 'NSIS System Plug-in', i 0)"
524 </pre></blockquote>
525 <blockquote><pre>
526 <a name="get"></a>System::<b>Get</b> "user32::MessageBox(p $HWNDPARENT, t 'This is a default text', t 'Default', i 0)"
527 Pop $0
528 System::<b>Call</b> "$0"
529 </pre></blockquote>
530 <blockquote><pre>
531 System::<b>Get</b> "user32::MessageBox(p $HWNDPARENT, t 'This is a default text', \
532 t 'Default', i 0x1|0x10)"
533 Pop $0
534 System::<b>Call</b> "$0(, 'This is a System::Get test', 'NSIS System Plug-in',)"
535 </pre></blockquote>
536 <blockquote><pre>
537 <a name="pointer"></a>System::<b>Call</b> "advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2"
538 DetailPrint "User name - $0"
539 DetailPrint "String length - $1"
540 DetailPrint "Return value - $2"
541 </pre></blockquote>
542 <blockquote><pre>
543 <a name="structaddr"></a>System::Alloc 4
544 Pop $0
545 System::<b>Call</b> "*$0(i 5)" ; Write
546 System::<b>Call</b> "*$0(i .r1)" ; Read
547 System::Free $0
548 DetailPrint $1
549 </pre></blockquote>
550 <blockquote><pre>
551 <a name="newstruct"></a>System::<b>Call</b> "*(i 5) p .r0"
552 System::<b>Call</b> "*$0(i .r1)"
553 System::Free $0
554 DetailPrint $1
555 </pre></blockquote>
556 <a name="structsize"></a><blockquote><pre>
557 System::Call '*0(p, <b>&amp;l.r2,</b> &amp;t2)' ; &amp;l. is not part of the struct
558 DetailPrint "Struct size=$2"
559 </pre></blockquote>
560 <a name="structsizemember"></a><blockquote><pre>
561 System::Call '*(<b>&amp;l4</b>,i,i,i,i,&amp;t128)p.r1' ; Fills dwOSVersionInfoSize with the struct size as a int32
562 ${If} $1 Z&lt;&gt; 0
563 System::Call 'kernel32::GetVersionEx(pr1)i.r0'
564 System::Call '*$1(i,i.R1,i.R2,i.R3)'
565 System::Free $1
566 ${IfThen} $0 &lt;&gt; 0 ${|} DetailPrint "v$R1.$R2.$R3" ${|}
567 ${EndIf}
568 </pre></blockquote>
569 <blockquote><pre>
570 <a name="directvarmemparam"></a>System::<b>Call</b> "user32::GetClientRect(p $hwndparent, @ r0)"
571 System::<b>Call</b> "*$0(i,i,i.r1,i.r2)"
572 DetailPrint ClientRect=$1x$2
573 </pre></blockquote>
574 <blockquote><pre>
575 <a name="com"></a># defines
576 !define CLSCTX_INPROC_SERVER 1
577 !define CLSID_ActiveDesktop {75048700-EF1F-11D0-9888-006097DEACF9}
578 !define IID_IActiveDesktop {F490EB00-1240-11D1-9888-006097DEACF9}
579 # create IActiveDesktop interface
580 System::<b>Call</b> "ole32::CoCreateInstance( \
581 g '${CLSID_ActiveDesktop}', p 0, \
582 i ${CLSCTX_INPROC_SERVER}, \
583 g '${IID_IActiveDesktop}', *p .r0) i.r1"
584 StrCmp $1 0 0 end
585 # call IActiveDesktop->GetWallpaper
586 System::<b>Call</b> "$0->4(w .r2, i ${NSIS_MAX_STRLEN}, i 0)"
587 # call IActiveDesktop->Release
588 System::<b>Call</b> "$0->2()"
589 # print result
590 DetailPrint $2
591 end:
592 </pre></blockquote>
593 <blockquote><pre>
594 InitPluginsDir
595 File "/oname=$PLUGINSDIR\MyDLL.dll" MyDLL.dll
596 System::<b>Call</b> 'KERNEL32::AddDllDirectory(w "$PLUGINSDIR")'
597 System::<b>Call</b> 'KERNEL32::LoadLibrary(t "$PLUGINSDIR\MyDLL.dll")p.r1'
598 System::<b>Call</b> 'MyDLL::MyFunc(i 5) ? u'
599 System::<b>Call</b> 'KERNEL32::FreeLibrary(pr1)'
600 Delete $PLUGINSDIR\MyDLL.dll
601 </pre></blockquote>
602 <blockquote><pre>
603 <a name="callback"></a>System::<b>Get</b> "(p.r1, p) iss"
604 Pop $R0
605 System::<b>Call</b> "user32::EnumChildWindows(p $HWNDPARENT, k R0, p) i.s"
606 loop:
607 Pop $0
608 StrCmp $0 "callback1" 0 done
609 System::<b>Call</b> "user32::GetWindowText(pr1,t.r2,i${NSIS_MAX_STRLEN})"
610 System::<b>Call</b> "user32::GetClassName(pr1,t.r3,i${NSIS_MAX_STRLEN})"
611 IntFmt $1 "0x%X" $1
612 DetailPrint "$1 - [$3] $2"
613 Push 1 # callback's return value
614 System::<b>Call</b> "$R0"
615 Goto loop
616 done:
617 System::Free $R0
618 DetailPrint "EnumChildWindows returned $0"
619 </pre></blockquote>
620 <a name="v2callback"></a><blockquote><pre>
621 System::Get '(m.r1)ir2r0 <b>?2</b>' ; v2 syntax
622 Pop $9
623 System::Call 'kernel32::EnumSystemLocalesA(k r9, i 0)'
624 loop:
625 StrCmp <b>$0 "callback$9"</b> 0 done
626 DetailPrint "Locale: $1"
627 StrCpy $2 1 ; EnumLocalesProc return value
628 System::Call $9 ; return from EnumLocalesProc
629 Goto loop
630 done:
631 System::Free $9
632 </pre></blockquote>
633 <a name="v2typealign"></a><blockquote><pre>
634 System::Call '*(&amp;t50 "!")p.r2' ; DecimalSep
635 System::Call '*(&amp;t50 "`")p.r3' ; ThousandSep
636 System::Call '*(i 2, i 0, i 3, <b>P r2, P r3</b>, i 1)p.r1 <b>?2</b>'
637 System::Call 'kernel32::GetNumberFormat(i 0, i 0, t "1337.666" r4, p r1, t.r5, i ${NSIS_MAX_STRLEN})'
638 DetailPrint "Custom formatted $4: $5"
639 System::Free $3
640 System::Free $2
641 System::Free $1
642 </pre></blockquote>
643 <blockquote><pre>
644 <a name="repeat"></a>!define MB "user32::MessageBox(p$HWNDPARENT,t,t'NSIS System Plug-in',i0)"
645 System::<b>Call</b> "${MB}(,'my message',,)"
646 System::<b>Call</b> "${MB}(,'another message',,) i.r0"
647 MessageBox MB_OK "last call returned $0"
648 </pre></blockquote>
649 <blockquote><pre>
650 <a name="repeatproc"></a>System::<b>Call</b> "user32::SendMessage(p $HWNDPARENT, t 'test', t 'test', p 0) p.s ? \
651 e (,t'test replacement',,) i.r0 ? !e #user32::MessageBox"
652 DetailPrint $0
653 ClearErrors
654 Pop $0
655 IfErrors good
656 MessageBox MB_OK "this message box will never be reached"
657 good:
658 </pre></blockquote>
659 </blockquote>
660 </li>
661 </ul>
662
663 </div>
664
665 <h3><a name="64bitfuncs"></a>64-bit Functions</h3>
666
667 <div>
668
669 <ul>
670
671 <li>
672 <b id="Int64Op">Int64Op</b> <i>ARG1</i> <i>OP</i> [<i>ARG2</i>]
673 <blockquote>
674 <p>Performs <i>OP</i> on <i>ARG1</i> and optionally <i>ARG2</i> and returns the result on the stack. Both <i>ARG1</i> and <i>ARG2</i> are 64-bit integers. This means they can range between -2^63 and 2^63 - 1.</p>
675 <h4>Available Operations</h4>
676 <ul>
677 <li>Addition -- <b>+</b></li>
678 <li>Subtraction -- <b>-</b></li>
679 <li>Multiplication -- <b>*</b></li>
680 <li>Division -- <b>/</b></li>
681 <li>Modulo -- <b>%</b></li>
682 <li>Shift left -- <b>&lt;&lt;</b></li>
683 <li>Arithmetic shift right -- <b>&gt;&gt;</b></li>
684 <li>Logical shift right -- <b>&gt;&gt;&gt;</b></li>
685 <li>Bitwise or -- <b>|</b></li>
686 <li>Bitwise and -- <b>&amp;</b></li>
687 <li>Bitwise xor -- <b>^</b></li>
688 <li>Bitwise not (one argument) -- <b>~</b></li>
689 <li>Logical not (one argument) -- <b>!</b></li>
690 <li>Logical or -- <b>||</b></li>
691 <li>Logical and -- <b>&amp;&amp;</b></li>
692 <li>Less than -- <b>&lt;</b></li>
693 <li>Equals -- <b>=</b></li>
694 <li>Greater than -- <b>&gt;</b></li>
695 </ul>
696
697 <h4>Usage Examples</h4>
698
699 <blockquote><pre>
700 System::<b>Int64Op</b> 5 + 5
701 Pop $0
702 DetailPrint "5 + 5 = $0" # 10
703 </pre></blockquote>
704 <blockquote><pre>
705 System::<b>Int64Op</b> 526355 * 1565487
706 Pop $0
707 DetailPrint "526355 * 1565487 = $0" # 824001909885
708 </pre></blockquote>
709 <blockquote><pre>
710 System::<b>Int64Op</b> 5498449498849818 / 3
711 Pop $0
712 DetailPrint "5498449498849818 / 3 = $0" # 1832816499616606
713 </pre></blockquote>
714 <blockquote><pre>
715 System::<b>Int64Op</b> 0x89498A198E4566C % 157
716 Pop $0
717 DetailPrint "0x89498A198E4566C % 157 = $0" # 118
718 </pre></blockquote>
719 <blockquote><pre>
720 System::<b>Int64Op</b> 1 &lt;&lt; 62
721 Pop $0
722 DetailPrint "1 &lt;&lt; 62 = $0" # 4611686018427387904
723 </pre></blockquote>
724 <blockquote><pre>
725 System::<b>Int64Op</b> 0x4000000000000000 &gt;&gt; 62
726 Pop $0
727 DetailPrint "0x4000000000000000 &gt;&gt; 62 = $0" # 1
728
729 System::<b>Int64Op</b> 0x8000000000000000 &gt;&gt; 1
730 Pop $0
731 DetailPrint "0x8000000000000000 &gt;&gt; 1 = $0" # -4611686018427387904 (0xC000000000000000)
732
733 System::<b>Int64Op</b> 0x8000000000000000 &gt;&gt;&gt; 1
734 Pop $0
735 DetailPrint "0x8000000000000000 &gt;&gt;&gt; 1 = $0" # 4611686018427387904 (0x4000000000000000)
736 </pre></blockquote>
737 <blockquote><pre>
738 System::<b>Int64Op</b> 0x12345678 &amp; 0xF0F0F0F0
739 Pop $0
740 # IntFmt is 32-bit, this is just for the example
741 IntFmt $0 "0x%X" $0
742 DetailPrint "0x12345678 &amp; 0xF0F0F0F0 = $0" # 0x10305070
743 </pre></blockquote>
744 <blockquote><pre>
745 System::<b>Int64Op</b> 1 ^ 0
746 Pop $0
747 DetailPrint "1 ^ 0 = $0" # 1
748 </pre></blockquote>
749 <blockquote><pre>
750 System::<b>Int64Op</b> 1 || 0
751 Pop $0
752 DetailPrint "1 || 0 = $0" # 1
753 </pre></blockquote>
754 <blockquote><pre>
755 System::<b>Int64Op</b> 1 &amp;&amp; 0
756 Pop $0
757 DetailPrint "1 &amp;&amp; 0 = $0" # 0
758 </pre></blockquote>
759 <blockquote><pre>
760 System::<b>Int64Op</b> 9302157012375 &lt; 570197509190760
761 Pop $0
762 DetailPrint "9302157012375 &lt; 570197509190760 = $0" # 1
763 </pre></blockquote>
764 <blockquote><pre>
765 System::<b>Int64Op</b> 5168 &gt; 89873
766 Pop $0
767 DetailPrint "5168 &gt; 89873 = $0" # 0
768 </pre></blockquote>
769 <blockquote><pre>
770 System::<b>Int64Op</b> 189189 = 189189
771 Pop $0
772 DetailPrint "189189 = 189189 = $0" # 1
773 </pre></blockquote>
774 <blockquote><pre>
775 System::<b>Int64Op</b> 156545668489 ~
776 Pop $0
777 DetailPrint "156545668489 ~ = $0" # -156545668490
778 </pre></blockquote>
779 <blockquote><pre>
780 System::<b>Int64Op</b> 1 !
781 Pop $0
782 DetailPrint "1 ! = $0" # 0
783 </pre></blockquote>
784 </blockquote>
785 </li>
786
787 </ul>
788
789 </div>
790
791 <h2><a name="faq"></a>FAQ</h2>
792
793 <div>
794
795 <ul>
796
797 <li>
798 <b>Q:</b> How can I pass structs to functions?
799 <blockquote>
800 <p><b>A:</b> First of all, you must allocate the struct. This can be done in two ways. You can either use <a href="#memfuncs">Alloc</a> or <a href="#callfuncs">Call</a> with the special struct allocation syntax. Next, if you need to pass data in the struct, you must fill it with data. Then you call the function with a pointer to the struct. Finally, if you want to read data from the struct which might have been written by the called function, you must use <a href="#callfuncs">Call</a> with the struct handling syntax. After all is done, it's important to remember to free the struct.</p>
801
802 <h4>Allocation</h4>
803
804 <blockquote><p>To allocate the struct using <a href="#memfuncs">Alloc</a>, you must know the size of the struct in bytes. Therefore, it would normally be easier to use <a href="#callfuncs">Call</a>. In this case it's easy to see the required size is 16 bytes, but other cases might not be that trivial. In both cases, the struct address will be located on the top of the stack and should be retrieved using Pop.</p>
805
806 <blockquote><pre>
807 System::Alloc 16
808 </pre></blockquote>
809
810 <blockquote><pre>
811 System::Call "*(i, i, i, t)p.s"
812 </pre></blockquote>
813
814 </blockquote>
815
816 <h4>Setting Data</h4>
817
818 <blockquote><p>Setting data can be done using <a href="#callfuncs">Call</a>. It can be done in the allocation stage, or in another stage using the struct handling syntax.</p>
819
820 <blockquote><pre>
821 System::Call "*(i 5, i 2, i 513, t 'test')p.s"
822 </pre></blockquote>
823
824 <blockquote><pre>
825 # assuming the struct's memory address is kept in $0
826 System::Call "*$0(i 5, i 2, i 513, t 'test')"
827 </pre></blockquote>
828
829 </blockquote>
830
831 <h4>Passing to the Function</h4>
832
833 <blockquote><p>As all allocation methods return an address, the type of the passed data should be an integer, an address in memory.</p>
834
835 <blockquote><pre>
836 # assuming the struct's memory address is kept in $0
837 System::Call "dll::func(p r0)"
838 </pre></blockquote>
839
840 </blockquote>
841
842 <h4>Reading Data</h4>
843
844 <blockquote><p>Reading data from the struct can be done using the same syntax as setting it. The only difference is that the destination part of the parameter will be set and the source part will be omitted using a dot.</p>
845
846 <blockquote><pre>
847 # assuming the struct's memory address is kept in $0
848 System::Call "*$0(i .r0, i .r1, i .r2, t .r3)"
849 DetailPrint "first int = $0"
850 DetailPrint "second int = $1"
851 DetailPrint "third int = $2"
852 DetailPrint "string = $3"
853 </pre></blockquote>
854
855 </blockquote>
856
857 <h4>Freeing Memory</h4>
858
859 <blockquote><p>Memory is freed using <a href="#memfuncs">Free</a>.</p>
860
861 <blockquote><pre>
862 # assuming the struct's memory address is kept in $0
863 System::Free $0
864 </pre></blockquote>
865
866 </blockquote>
867
868 <h4>A Complete Example</h4>
869
870 <blockquote><pre>
871 # allocate
872 System::Call "*(i,i,p,p,p,p,p,p)p.r1"
873 # call
874 System::Call "Kernel32::GlobalMemoryStatus(p r1)"
875 # get
876 System::Call "*$1(i.r2, i.r3, p.r4, p.r5, p.r6, p.r7, p.r8, p.r9)"
877 # free
878 System::Free $1
879 # print
880 DetailPrint "Structure size: $2 bytes"
881 DetailPrint "Memory load: $3%"
882 DetailPrint "Total physical memory: $4 bytes"
883 DetailPrint "Free physical memory: $5 bytes"
884 DetailPrint "Total page file: $6 bytes"
885 DetailPrint "Free page file: $7 bytes"
886 DetailPrint "Total virtual: $8 bytes"
887 DetailPrint "Free virtual: $9 bytes"
888 </pre></blockquote>
889
890 </blockquote>
891 </li>
892
893 </ul>
894
895 </div>
896
897 </body>
898 </html>