<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 <ahref="https://msdn.microsoft.com/en-us/library/aa364975">GetLogicalDriveStrings</a> to get a list of available drives on the user's computer.</p>
<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>
<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>
<h4>Usage Example</h4>
<blockquote><pre>
System::<b>StrAlloc</b> 64 ; String buffer for 63 characters and \0 termination.
Pop $0
DetailPrint "A string buffer for 64 characters allocated at $0"
<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>
<h4>Usage example</h4>
<blockquote><pre>
# allocate a buffer and put 'test string' and an int in it
<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>
<h4>Available Operations</h4>
<ul>
<li>To push $<i>#</i>, use p<i>#</i>, where <i>#</i> is a digit from 0 to 9.</li>
<li>To pop $<i>#</i>, use r<i>#</i>, where <i>#</i> is a digit from 0 to 9.</li>
<li>To push $R<i>#</i>, use P<i>#</i>, where <i>#</i> is a digit from 0 to 9.</li>
<li>To pop $R<i>#</i>, use R<i>#</i>, where <i>#</i> is a digit from 0 to 9.</li>
<li>To push $0-$9 and $R0-$R9 to System's private stack, use s or S.</li>
<li>To pop $0-$9 and $R0-$R9 from System's private stack, use l or L.</li>
<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>
<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>
<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>
<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>
<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 <ahref="#repeat">last two examples</a> show this.</p>
<p><i>PROC</i> can also be <ahref="#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>
<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 <ahref="#pointer">usage example</a> is available. <ahref="#memfuncs">Alloc</a> returns addresses and its return value should therefore be used with `p', without an asterisk.</p>
<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 <ahref="#directvarmemparam">not necessary</a>.
<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, <ahref="https://msdn.microsoft.com/en-us/library/ms633494">EnumChildWindows</a> uses a <ahref="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>
<p>Creation of callback functions is done using <ahref="#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>
<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>
<p>After you've processed the callback call, you should use <ahref="#callfuncs">Call</a>, passing it the value returned by <ahref="#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>
<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>
<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>
<li>Libraries in the system32 directory can be loaded without a path. All other libraries should be loaded with a <ahref="#funcqpath">quoted full path</a>.</li>
<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>
</tr>
<tr>
<th>n</th>
<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>
</tr>
<tr>
<th>s</th>
<td>Use general Stack. Whenever the first callback defined the system starts using the temporary stacks for function calls.</td>
</tr>
<tr>
<th>e</th>
<td>Call GetLastError() after procedure end and push result on stack.</td>
</tr>
<tr>
<th>u</th>
<td>Unload DLL after call (using FreeLibrary, so you'll be able to delete it for example).</td>
<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>
<p><b>A:</b> First of all, you must allocate the struct. This can be done in two ways. You can either use <ahref="#memfuncs">Alloc</a> or <ahref="#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 <ahref="#callfuncs">Call</a> with the struct handling syntax. After all is done, it's important to remember to free the struct.</p>
<h4>Allocation</h4>
<blockquote><p>To allocate the struct using <ahref="#memfuncs">Alloc</a>, you must know the size of the struct in bytes. Therefore, it would normally be easier to use <ahref="#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>
<blockquote><p>Setting data can be done using <ahref="#callfuncs">Call</a>. It can be done in the allocation stage, or in another stage using the struct handling syntax.</p>
<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>
<blockquote><pre>
# assuming the struct's memory address is kept in $0
System::Call "*$0(i .r0, i .r1, i .r2, t .r3)"
DetailPrint "first int = $0"
DetailPrint "second int = $1"
DetailPrint "third int = $2"
DetailPrint "string = $3"
</pre></blockquote>
</blockquote>
<h4>Freeing Memory</h4>
<blockquote><p>Memory is freed using <ahref="#memfuncs">Free</a>.</p>
<blockquote><pre>
# assuming the struct's memory address is kept in $0