NSIS/Contrib/System/System.html

761 lines
24 KiB
HTML
Raw Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>NSIS System Plug-in</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
</head>
<body>
<h1>NSIS System Plug-in</h1>
<p><i>&copy; brainsucker (Nik Medved), 2002</i></p>
<h2>Table of Contents</h2>
<ul>
<li><a href="#intro">Introduction</a></li>
<li>
<a href="#funcs">Available Functions</a>
<ul>
<li><a href="#memfuncs">Memory Related Functions</a></li>
<li><a href="#callfuncs">Calling Functions</a></li>
<li><a href="#64bitfuncs">64-bit Functions</a></li>
</ul>
</li>
<li><a href="#faq">FAQ</a></li>
</ul>
<h2><a name="intro"></a>Introduction</h2>
<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="http://msdn.microsoft.com/library/en-us/fileio/base/getlogicaldrivestrings.asp">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>Programming knowledge is highly recommended in order to understand the System plug-in.</p>
<h4>Usage Examples From The Archive</h4>
<ul>
<li><a href="http://nsis.sourceforge.net/archive/viewpage.php?pageid=257">Get local time</a></li>
<li><a href="http://nsis.sourceforge.net/archive/viewpage.php?pageid=439">Register conduits with Palm HotSync</a></li>
<li><a href="http://nsis.sourceforge.net/archive/viewpage.php?pageid=122">Get free memory</a></li>
<li><a href="http://nsis.sourceforge.net/archive/viewpage.php?pageid=190">Read REG_MULTI_SZ</a></li>
<li><a href="http://nsis.sourceforge.net/archive/viewpage.php?pageid=464">Get disk serial number</a></li>
</ul>
<h2><a name="funcs"></a>Available Functions</h2>
<h3><a name="memfuncs"></a>Memory Related Functions</h3>
<div>
<ul>
<li>
<b>Alloc</b> <i>SIZE</i>
<blockquote>
<p>Allocates <i>SIZE</i> bytes and returns a memory address on the stack.</p>
<h4>Usage Example</h4>
<blockquote><pre>
System::<b>Alloc</b> 64
Pop $0
DetailPrint "64 bytes allocated at $0"
System::Free $0
</pre></blockquote>
</blockquote>
</li>
<li>
<b>Copy</b> [/<i>SIZE</i>] <i>DESTINATION</i> <i>SOURCE</i>
<blockquote>
<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
System::Call "*(&amp;t1024 'test string', i 5) i .s"
Pop $0
# copy to an automatically created buffer
System::<b>Copy</b> 0 $0
Pop $1
# get string and int in $1 buffer
System::Call "*$1(&amp;t1024 .r2, i .r3)"
# free buffer
System::Free $1
# print result
DetailPrint $2
DetailPrint $3
# copy to our own buffer
System::Alloc 1028
Pop $1
System::<b>Copy</b> $1 $0
# get string and int in $1 buffer
System::Call "*$1(&amp;t1024 .r2, i .r3)"
# free
System::Free $0
System::Free $1
# print result
DetailPrint $2
DetailPrint $3
</pre></blockquote>
</blockquote>
</li>
<li>
<b>Free</b> <i>ADDRESS</i>
<blockquote>
<p>Frees <i>ADDRESS</i>.</p>
<h4>Usage Example</h4>
<blockquote><pre>
System::Alloc 64
Pop $0
DetailPrint "64 bytes allocated at $0"
System::<b>Free</b> $0
</pre></blockquote>
</blockquote>
</li>
<li>
<b>Store</b> "<i>OEPRATION</i> [<i>OEPRATION</i> [<i>OEPRATION</i> ...]]"
<blockquote>
<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>
</ul>
<p>Note that the System's private stack will be lost when the System plug-in is unloaded from NSIS. If you want to use it, you must keep the System plug-in loaded into NSIS. To do that, use SetPluginUnload or the /NOUNLOAD flag in the NSIS script.</p>
<h4>Usage Examples</h4>
<blockquote><pre>
StrCpy $0 "test"
System::<b>Store</b> "p0"
Pop $1
DetailPrint "$0 = $1"
</pre></blockquote>
<blockquote><pre>
StrCpy $2 "test"
System::<b>Store</b> "p2 R2"
DetailPrint "$2 = $R2"
</pre></blockquote>
<blockquote><pre>
StrCpy $3 "test"
System::<b>Store</b> /NOUNLOAD "s"
StrCpy $3 "another test"
System::<b>Store</b> "l"
DetailPrint $3
</pre></blockquote>
<blockquote><pre>
System::<b>Store</b> "r4" "test"
DetailPrint $4
</pre></blockquote>
</blockquote>
</li>
</ul>
</div>
<h3><a name="callfuncs"></a>Calling Functions</h3>
<div>
<ul>
<li><b>Call</b> <i>PROC</i> [( <i>PARAMS</i> ) [<i>RETURN</i> [? <i>OPTIONS</i>]]]</li>
<li><b>Get</b> <i>PROC</i> [( <i>PARAMS</i> ) [<i>RETURN</i> [? <i>OPTIONS</i>]]]
<blockquote>
<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 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 <a href="#repeat">last two examples</a> show this.</p>
<p><b>(can't get a working example)</b> <i>PROC</i> can also be repeated but must be prefixed with a hash sign (`#').</p>
<h4>Possible <i>PROC</i> values and Meanings</h4>
<blockquote>
<table>
<tr>
<th>Value</th>
<th>Meaning</th>
<th>Example</th>
</tr>
<tr>
<th><i>DLL</i>::<i>FUNC</i></th>
<td><i>FUNC</i> exported from <i>DLL</i></td>
<td><a href="#func">user32::MessageBox</a></td>
</tr>
<tr>
<th>::<i>ADDR</i></th>
<td>Function located at <i>ADDR</i></td>
<td><a href="#funcaddr">see below</a></td>
</tr>
<tr>
<th>*<i>ADDR</i></th>
<td>Structure located at <i>ADDR</i></td>
<td><a href="#structaddr">see below</a></td>
</tr>
<tr>
<th>*</th>
<td>New structure</td>
<td><a href="#newstruct">see below</a></td>
</tr>
<tr>
<th><i>IPTR</i>-><i>IDX</i></th>
<td>Member indexed <i>IDX</i> from<br/>interface pointed by <i>IPTR</i></td>
<td><a href="#com">see below</a></td>
</tr>
<tr>
<th>&lt;nothing&gt;</th>
<td>New callback function</td>
<td><a href="#callback">see below</a></td>
</tr>
<tr>
<th><i>PROC</i></th>
<td><i>PROC</i> returned by Get</td>
<td><a href="#get">see below</a></td>
</tr>
</table>
</blockquote>
<h4>Available Parameter Types</h4>
<blockquote>
<table>
<tr>
<th>Type</th>
<th>Meaning</th>
</tr>
<tr>
<th>v</th>
<td>void (generally for return)</td>
<td></td>
</tr>
<tr>
<th>i</th>
<td>int (includes char, byte, short, handles, pointers and so on)</td>
</tr>
<tr>
<th>l</th>
<td>large integer, int64</td>
</tr>
<tr>
<th>t</th>
<td>text, string (pointer to first character)</td>
</tr>
<tr>
<th>w</th>
<td>WCHAR text, Unicode string</td>
</tr>
<tr>
<th>g</th>
<td>GUID</td>
</tr>
<tr>
<th>k</th>
<td>callback</td>
</tr>
<tr>
<th>&amp;v<i>N</i></th>
<td><i>N</i> bytes padding (structures only)</td>
</tr>
<tr>
<th>&amp;i<i>N</i></th>
<td>integer of <i>N</i> bytes (structures only)</td>
</tr>
<tr>
<th>&amp;l</th>
<td>structure size (structures only)</td>
</tr>
<tr>
<th>&amp;t<i>N</i></th>
<td><i>N</i> bytes of text (structures only)</td>
</tr>
<tr>
<th>&amp;w<i>N</i></th>
<td><i>N</i> bytes of Unicode text (structures only)</td>
</tr>
<tr>
<th>&amp;g<i>N</i></th>
<td><i>N</i> bytes of GUID (structures only)</td>
</tr>
</table>
</blockquote>
<h4>Available Sources and Destinations</h4>
<blockquote>
<table>
<tr>
<th>Type</th>
<th>Meaning</th>
</tr>
<tr>
<th>.</th>
<td>ignored</td>
<td></td>
</tr>
<tr>
<th><i>number</i></th>
<td>concrete hex, decimal or octal integer value. several integers can be or'ed using the pipe symbol (`|')</td>
</tr>
<tr>
<th>'<i>string</i>'<br/>"<i>string</i>"<br/>`<i>string</i>`</th>
<td>concrete string value</td>
</tr>
<tr>
<th><i>r0</i> through <i>r9</i></th>
<td>$0 through $9 respectively</td>
</tr>
<tr>
<th><i>r10</i> through <i>r19</i><br/><i>R0</i> through <i>R9</i></th>
<td>$R0 through $R9 respectively</td>
</tr>
<tr>
<th>c</th>
<td>$CMDLINE</td>
</tr>
<tr>
<th>d</th>
<td>$INSTDIR</td>
</tr>
<tr>
<th>o</th>
<td>$OUTDIR</td>
</tr>
<tr>
<th>e</th>
<td>$EXEDIR</td>
</tr>
<tr>
<th>a</th>
<td>$LANG</td>
</tr>
<tr>
<th>s</th>
<td>NSIS stack</td>
</tr>
<tr>
<th>n</th>
<td>null for source, no output required for destination</td>
</tr>
</table>
</blockquote>
<h4>Callbacks</h4>
<blockquote>
<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="http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/EnumChildWindows.asp">EnumChildWindows</a> uses a <a href="http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/EnumChildProc.asp">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 <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>
<blockquote><pre>System::Get "(i .r0, i .r1) iss"</pre></blockquote>
<p>To pass a callback to a function, use the k type.</p>
<blockquote><pre>System::Get "(i .r0, i .r1) isR0"
Pop $0
System::Call "dll::UseCallback(k r0)"</pre></blockquote>
<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>
<blockquote><pre>System::Call "(i .r0, i .r1) isR0"
Pop $0
System::Call "dll::UseCallback(k r0)"
StrCmp $R0 "callback1" 0 +2
DetailPrint "UseCallback passed ($0, $1) to the callback"
</pre></blockquote>
<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. 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.</p>
<blockquote><pre>System::Call "(i .r0, i .r1) isR0"
Pop $0
System::Call "dll::UseCallback(k r0)"
loop:
StrCmp $R0 "callback1" 0 done
DetailPrint "UseCallback passed ($0, $1) to the callback"
Push 1 # return value of the callback
System::Call $0 # tell system to return from the callback
Goto loop
done:
</pre></blockquote>
<p>A complete working <a href="#callback">example</a> is available in the usage examples section.</p>
</blockquote>
<h4>Notes</h4>
<blockquote>
<ul>
<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. Remember the index is zero based.</li>
<li>Always remember to use NSIS's /NOUNLOAD switch or SetPluginUnload when working with callbacks. The System plug-in will not be able to process the callback calls right if it's unloaded.</li>
<li>If a function can't be found, an `A' 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>
</ul>
</blockquote>
<h4>Available Options</h4>
<blockquote>
<table>
<tr>
<th>Option</th>
<th>Meaning</th>
</tr>
<tr>
<th>c</th>
<td>cdecl calling convention (the stack restored by caller). By default stdcall calling convention is used (the stack restored by callee).</td>
<td></td>
</tr>
<tr>
<th>r</th>
<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>
</tr>
</table>
</blockquote>
<h4>Usage Examples</h4>
<blockquote><pre>
<a name="func"></a>System::<b>Call</b> "user32::MessageBox(i $HWNDPARENT, t 'NSIS System Plug-in', t 'Test', i 0)"
</pre></blockquote>
<blockquote><pre>
<a name="funcaddr"></a>System::<b>Call</b> "kernel32::GetModuleHandle(t 'user32.dll') i .s"
System::<b>Call</b> "kernel32::GetProcAddress(i s, t 'MessageBoxA') i .r0"
System::<b>Call</b> "::$0(i $HWNDPARENT, t 'GetProcAddress test', t 'NSIS System Plug-in', i 0)"
</pre></blockquote>
<blockquote><pre>
<a name="get"></a>System::<b>Get</b> "user32::MessageBox(i $HWNDPARENT, t 'This is a default text', t 'Default', i 0)"
Pop $0
System::<b>Call</b> "$0"
</pre></blockquote>
<blockquote><pre>
System::<b>Get</b> "user32::MessageBox(i $HWNDPARENT, t 'This is a default text', \
t 'Default', i 0x1|0x10)"
Pop $0
System::<b>Call</b> "$0(, 'This is a System::Get test', 'NSIS System Plug-in',)"
</pre></blockquote>
<blockquote><pre>
<a name="structaddr"></a>System::Alloc 4
Pop $0
System::<b>Call</b> "*$0(i 5)"
System::<b>Call</b> "*$0(i .r1)"
DetailPrint $1
</pre></blockquote>
<blockquote><pre>
<a name="newstruct"></a>System::<b>Call</b> "*(i 5) i .r0"
System::<b>Call</b> "*$0(i .r1)"
DetailPrint $1
</pre></blockquote>
<blockquote><pre>
<a name="com"></a># defines
!define CLSCTX_INPROC_SERVER 1
!define CLSID_ActiveDesktop {75048700-EF1F-11D0-9888-006097DEACF9}
!define IID_IActiveDesktop {F490EB00-1240-11D1-9888-006097DEACF9}
# create IActiveDesktop interface
System::<b>Call</b> "ole32::CoCreateInstance( \
g '${CLSID_ActiveDesktop}', i 0, \
i ${CLSCTX_INPROC_SERVER}, \
g '${IID_IActiveDesktop}', *i .r0) i.r1"
StrCmp $1 0 0 end
# call IActiveDesktop->GetWallpaper
System::<b>Call</b> "$0->4(w .r2, i ${NSIS_MAX_STRLEN}, i 0)"
# call IActiveDesktop->Release
System::<b>Call</b> "$0->2()"
# print result
DetailPrint $2
end:
</pre></blockquote>
<blockquote><pre>
InitPluginsDir
SetOutPath $PLUGINSDIR
File MyDLL.dll
System::<b>Call</b> "MyDLL::MyFunc(i 5) ? u"
Delete $PLUGINSDIR\MyDLL.dll
</pre></blockquote>
<blockquote><pre>
<a name="callback"></a>SetPluginUnload alwaysoff
System::<b>Get</b> "(i.r1, i) iss"
Pop $R0
System::<b>Call</b> "user32::EnumChildWindows(i $HWNDPARENT, k R0, i) i.s"
loop:
Pop $0
StrCmp $0 "callback1" 0 done
System::<b>Call</b> "user32::GetWindowText(ir1,t.r2,i${NSIS_MAX_STRLEN})"
System::<b>Call</b> "user32::GetClassName(ir1,t.r3,i${NSIS_MAX_STRLEN})"
IntFmt $1 "0x%X" $1
DetailPrint "$1 - [$3] $2"
Push 1 # callback's return value
System::<b>Call</b> "$R0"
Goto loop
done:
SetPluginUnload manual
System::Free $R0
</pre></blockquote>
<blockquote><pre>
<a name="repeat"></a>!define MB "user32::MessageBox(i$HWNDPARENT,t,t'NSIS System Plug-in',i0)"
System::<b>Call</b> "${MB}(,'my message',,)"
System::<b>Call</b> "${MB}(,'another message',,) i.r0"
MessageBox MB_OK "last call returned $0"
</pre></blockquote>
<blockquote><pre>
System::<b>Call</b> "user32::MessageBox(i $HWNDPARENT, t 'test', t 'test', i 0) i.s ? \
e (,t'test replacement',,) i.r0 ? !e"
DetailPrint $0
ClearErrors
Pop $0
IfErrors good
MessageBox MB_OK "this message box will never be reached"
good:
</pre></blockquote>
</blockquote>
</li>
</ul>
</div>
<h3><a name="64bitfuncs"></a>64-bit Functions</h3>
<div>
<ul>
<li>
<b>Int64Op</b> <i>ARG1</i> <i>OP</i> [<i>ARG2</i>]
<blockquote>
<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>
<h4>Available Operations</h4>
<ul>
<li>Addition -- <b>+</b></li>
<li>Subtraction -- <b>-</b></li>
<li>Multiplication -- <b>*</b></li>
<li>Division -- <b>/</b></li>
<li>Module -- <b>%</b></li>
<li>Bitwise or -- <b>|</b></li>
<li>Bitwise and -- <b>&amp;</b></li>
<li>Bitwise xor -- <b>^</b></li>
<li>Logical or -- <b>||</b></li>
<li>Logical and -- <b>&amp;&amp;</b></li>
<li>Less than -- <b>&lt;</b></li>
<li>Greater than -- <b>&gt;</b></li>
<li>Equals -- <b>=</b></li>
<li>Bitwise not (one argument) -- <b>~</b></li>
<li>Logical not (one argument) -- <b>!</b></li>
</ul>
<h4>Usage Examples</h4>
<blockquote><pre>
System::<b>Int64Op</b> 5 + 5
Pop $0
DetailPrint "5 + 5 = $0" # 10
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 64 - 25
Pop $0
DetailPrint "64 - 25 = $0" # 39
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 526355 * 1565487
Pop $0
DetailPrint "526355 * 1565487 = $0" # 824001909885
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 5498449498849818 / 3
Pop $0
DetailPrint "5498449498849818 / 3 = $0" # 1832816499616606
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 0x89498A198E4566C % 157
Pop $0
DetailPrint "0x89498A198E4566C % 157 = $0" # 118
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 0xF0F0F0F | 0xF0F0FFF
Pop $0
IntFmt $0 "0x%X" $0
DetailPrint "0xF0F0F0F | 0xF0F0FFF = $0" # 0xF0F0FFF
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 0x12345678 &amp; 0xF0F0F0F0
Pop $0
IntFmt $0 "0x%X" $0
DetailPrint "0x12345678 &amp; 0xF0F0F0F0 = $0" # 0x10305070
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 1 ^ 0
Pop $0
DetailPrint "1 ^ 0 = $0" # 1
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 1 || 0
Pop $0
DetailPrint "1 || 0 = $0" # 1
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 1 &amp;&amp; 0
Pop $0
DetailPrint "1 &amp;&amp; 0 = $0" # 0
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 5168 &lt; 89873
Pop $0
DetailPrint "5168 &lt; 89873 = $0" # 1
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 5168 &gt; 89873
Pop $0
DetailPrint "5168 &gt; 89873 = $0" # 0
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 189189 = 189189
Pop $0
DetailPrint "189189 = 189189 = $0" # 1
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 1 ~
Pop $0
IntFmt $0 "0x%X" $0
DetailPrint "1 ~ = $0" # 0xFFFFFFFE
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 1 !
Pop $0
DetailPrint "1 ! = $0" # 0
</pre></blockquote>
</blockquote>
</li>
</ul>
</div>
<h2><a name="faq"></a>FAQ</h2>
<div>
<ul>
<li>
<b>Q:</b> How can I pass structs to functions?
<blockquote>
<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>
<h4>Allocation</h4>
<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>
<blockquote><pre>
System::Alloc 16
</pre></blockquote>
<blockquote><pre>
System::Call "*(i, i, i, t).s"
</pre></blockquote>
</blockquote>
<h4>Setting Data</h4>
<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>
<blockquote><pre>
System::Call "*(i 5, i 2, i 513, t 'test')"
</pre></blockquote>
<blockquote><pre>
# assuming the struct's memory address is kept in $0
System::Call "*$0(i 5, i 2, i 513, t 'test')"
</pre></blockquote>
</blockquote>
<h4>Passing to the Function</h4>
<blockquote><p>As all allocation methods return an address, the type of the passed data should be an integer, an address in memory.</p>
<blockquote><pre>
# assuming the struct's memory address is kept in $0
System::Call "dll::func(i r0)"
</pre></blockquote>
</blockquote>
<h4>Reading Data</h4>
<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 <a href="#memfuncs">Free</a>.</p>
<blockquote><pre>
# assuming the struct's memory address is kept in $0
System::Free $0
</pre></blockquote>
</blockquote>
<h4>A Complete Example</h4>
<blockquote><pre>
# allocate
System::Alloc 32
Pop $1
# call
System::Call "Kernel32::GlobalMemoryStatus(i r1)"
# get
System::Call "*$1(i.r2, i.r3, i.r4, i.r5, i.r6, i.r7, i.r8, i.r9)"
# free
System::Free $1
# print
DetailPrint "Structure size: $2 bytes"
DetailPrint "Memory load: $3%"
DetailPrint "Total physical memory: $4 bytes"
DetailPrint "Free physical memory: $5 bytes"
DetailPrint "Total page file: $6 bytes"
DetailPrint "Free page file: $7 bytes"
DetailPrint "Total virtual: $8 bytes"
DetailPrint "Free virtual: $9 bytes"
</pre></blockquote>
</blockquote>
</li>
</ul>
</div>
</body>
</html>