NSIS calls dll

Source: Internet
Author: User

Use System. dll to call an external DLL

Some installation processes need to call functions included in third-party DLL. The best example is to install a Palm (TM) channel.

Background information about System. dll

The System. dll plug-in (developed by Brainsucker) allows you to Call external DLL by providing the Call function. There are a lot of functions provided by System. dll, but they are not suitable here. To get more details about other functions, please lock the door, remove the phone, go to the Contrib/System directory, and read the documentation there.

Data Type
System. dll can identify the data type:

V-void (often used for return)
I-int (including char, byte, short, handle, pointer, etc)
L-long integer (int64 is known)
T-text, string (LPCSTR, pointer of the first character)
B-Boolean (true or false to be returned)-in fact, this type is meaningless-> generally, it can be replaced by an integer ('0': '1 ')
K-callback. View the callback section of system.html.
*-Pointer-> Proc requires a pointer of this type, which affects the next character (parameter) [For example, '* I'-integer pointer]
Map System. dll variables to built-in variables in NSIS
If you do not need to return any data, there is nothing to call the point of an external function. System. dll can map function variables to NSIS script variables in the following ways:

NSIS $0... $9 can correspond to System. dll r0.. r9; NSIS $ r0.. $ R9 can also correspond to System. dll r10. r19

Each parameter is specified by type, input, and output. You can use a vertex to skip input or output. For example:

String (a character array pointer), input as 'easy call ':

T' easy call'
String (a character array pointer), input from $5, converted to the called array, and finally saved to $ R8:

T r5R8
An integer pointer, which is taken from $1 and placed in $2:

* I r1r2
A 64-bit integer pointer. The output is sent to the stack without input:

* L. s
Call a function in a third-party dll through System. DLL: Call. The Call usage is as follows:

System: Call 'yourdllname: YourDllFunction (I, * I, t) I (r0,. r1, r2). r3'

The (r0,. r1, r2). r3 section is used to transmit parameters between DLL and NSIS scripts. As you can see in this parameter list, the types can be separated from input and output. Each "(parameter list) Return Value" block does not need to be considered and/or added to the previous one. Here, the first block specifies the type and the second block specifies the input and output.

Before you start editing the NSIS script
Before editing the NSIS code, you must first understand the prototype of the function to be called. In this example, we use the 'cmgethotsyncexecpath' function in the Palm 'condmgr. dll. This function is used to return the complete path of 'HotSync.exe.

Function Definition

Int CmGetHotSyncExecPath (TCHAR * pPath, int * piSize );

Parameters

PPath is a pointer to the character buffer. Before returning, this is the path File Name of the HotSync manager installed.
PiSize is an integer pointer to the buffer size (TCHAR type) referenced by the pPath parameter.
Return Value:

0: no mistakes
-1: an ambiguous error occurs.
ERR_REGISTRY_ACCESS (-1006): The Palm configuration item cannot be accessed.
ERR_BUFFER_TOO_SMALL (-1010): the buffer is too small to store the request information.
ERR_INVALID_POINTER (-1013): The specified pointer is not a valid pointer.
Similarly, if the buffer size is too small, * the value in int Is the buffer size (TCHAR type ).

The above function definition is converted to System. dll definition:

CmGetHotSyncExecPath (t, * I) I

That is, it has a text variable, an integer pointer, and returns an integer.

Use external DLL Functions
After selecting what the function needs to do and how it is converted to the System. dll format, you can use this function in the NSIS script.

First, we recommend that you disable plug-in uninstallation when you need to call System. dll multiple times. According to Brainsucker (and others), this can speed up the execution of the installation package (reducing the time for unmounting and re-loading ).

Second, you must change the output directory to the directory where the DLL you want to use is located. If the DLL is in the system path, it also works, but it has not been tested.

The following code snippet releases condmgr. dll to a temporary directory, and then runs the CmGetHotSyncExecPath function to display the returned data and finally uninstall the System. dll plug-in.

  1. ; ***** Snip ****
  2. SetPluginUnload alwaysoff
  3. Function loadDll
  4. SetOutPath $ TEMP \ eInspect; create a temporary directory
  5. File bin \ CondMgr. dll; release DLL
  6. StrCpy $1 $ {NSIS_MAX_STRLEN}; assign memory to $0
  7. System: Call 'condmgr: CmGetHotSyncExecPath (t, * I) I (. r0, r1r1). rr2'
  8. DetailPrint 'path: "$0 "'
  9. DetailPrint "path length: $1"
  10. DetailPrint "Return Value: $2"
  11. The last plug-in call must have no/NOUNLOAD parameter; otherwise, NSIS cannot be deleted after installation.
  12. ; Temporary DLL file
  13. SetPluginUnload manual
  14. ; Nothing (to uninstall System. dll)
  15. System: Free 0
  16. FunctionEnd
  17. ; ***** Snip ****

Copy code

This function generates the following output on the View Details page:

Output directory: c: \ windows \ TEMP \ eInspect
Decompress: CondMgr. dll
Path: "C: \ Dave \ palm \ Hotsync.exe"
Path Length: 24
Return Value: 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.