/usr/share/doc/nsis/Docs/System/System.html is in nsis-doc 2.46-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | <!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>© 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 for good understanding of the System plug-in.</p>
<p>The most useful System plug-in functions (Call, Get and Debug) are not available when compiling with GCC. To work around this, either download a MSVC-compiled version or write your own plugin that calls the functions you need.</p>
<h4>Usage Examples From The Wiki</h4>
<ul>
<li><a href="http://nsis.sourceforge.net/wiki/Get_Local_Time">Get local time</a></li>
<li><a href="http://nsis.sourceforge.net/wiki/Registering_a_Palm_Com_Conduit">Register conduits with Palm HotSync</a></li>
<li><a href="http://nsis.sourceforge.net/wiki/Determining_free_memory_using_the_System_plugin">Get free memory</a></li>
<li><a href="http://nsis.sourceforge.net/wiki/REG_MULTI_SZ_Reader">Read REG_MULTI_SZ</a></li>
<li><a href="http://nsis.sourceforge.net/wiki/Get_Disk_Volume_Serial_Number">Get disk serial number</a></li>
<li><i><a href="http://nsis.sourceforge.net/Special:Search?search=System%3A%3ACall">Search all...</a></i></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 "*(&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(&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(&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>OPERATION</i> [<i>OPERATION</i> [<i>OPERATION</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>
<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> "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 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><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><nothing></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>m</th>
<td>ANSI text, string. (FYI: 'm' for multibyte string or 'w' flipped over.)</td>
</tr>
<tr>
<th>t</th>
<td>text, string (pointer to first character). <i>Like TCHAR*, it is a Unicode string in Unicode NSIS.</i></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>&v<i>N</i></th>
<td><i>N</i> bytes padding (structures only)</td>
</tr>
<tr>
<th>&i<i>N</i></th>
<td>integer of <i>N</i> bytes (structures only)</td>
</tr>
<tr>
<th>&l</th>
<td>structure size (structures only)</td>
</tr>
<tr>
<th>&t<i>N</i></th>
<td><i>N</i> bytes of text (structures only)</td>
</tr>
<tr>
<th>&w<i>N</i></th>
<td><i>N</i> bytes of Unicode text (structures only)</td>
</tr>
<tr>
<th>&g<i>N</i></th>
<td><i>N</i> bytes of GUID (structures only)</td>
</tr>
</table>
<p>Additionally, each type 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 `i' 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 `i', without an asterisk.</p>
</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>$LANGUAGE</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::Get "(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. 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>
<blockquote><pre>System::Get "(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
StrCpy $R0 "" # clear $R0 in case there are no more callback calls
System::Call $0 # tell system to return from the callback
Goto loop
done:
System::Free $0
</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>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="pointer"></a>System::<b>Call</b> "advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2"
DetailPrint "User name - $0"
DetailPrint "String length - $1"
DetailPrint "Return value - $2"
</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>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:
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::SendMessage(i $HWNDPARENT, t 'test', t 'test', i 0) i.s ? \
e (,t'test replacement',,) i.r0 ? !e #user32::MessageBox"
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>Modulo -- <b>%</b></li>
<li>Shift right -- <b>>></b></li>
<li>Shift left -- <b><<</b></li>
<li>Bitwise or -- <b>|</b></li>
<li>Bitwise and -- <b>&</b></li>
<li>Bitwise xor -- <b>^</b></li>
<li>Logical or -- <b>||</b></li>
<li>Logical and -- <b>&&</b></li>
<li>Less than -- <b><</b></li>
<li>Equals -- <b>=</b></li>
<li>Greater than -- <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> 1 << 62
Pop $0
DetailPrint "1 << 62 = $0" # 4611686018427387904
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 0x4000000000000000 >> 62
Pop $0
DetailPrint "0x4000000000000000 >> 62 = $0" # 1
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 0xF0F0F0F | 0xF0F0FFF
Pop $0
# IntFmt is 32-bit, this is just for the example
IntFmt $0 "0x%X" $0
DetailPrint "0xF0F0F0F | 0xF0F0FFF = $0" # 0xF0F0FFF
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 0x12345678 & 0xF0F0F0F0
Pop $0
# IntFmt is 32-bit, this is just for the example
IntFmt $0 "0x%X" $0
DetailPrint "0x12345678 & 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 && 0
Pop $0
DetailPrint "1 && 0 = $0" # 0
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 9302157012375 < 570197509190760
Pop $0
DetailPrint "9302157012375 < 570197509190760 = $0" # 1
</pre></blockquote>
<blockquote><pre>
System::<b>Int64Op</b> 5168 > 89873
Pop $0
DetailPrint "5168 > 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> 156545668489 ~
Pop $0
DetailPrint "1 ~ = $0" # -156545668490
</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)i.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')i.s"
</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>
|