NSIS使用System::Call调用自定义dll中的导出函数

本文详细介绍了如何使用NSIS的System.dll插件调用外部DLL中的函数,以CmGetHotSyncExecPath为例,解析了参数类型映射和返回值处理,展示了实际调用函数的NSIS脚本示例。
🐎 乙巳马年 · 皇城大门春联生成终端W

🐎 乙巳马年 · 皇城大门春联生成终端W

AI应用
文本生成
PALM

乙巳马年 · 皇城大门春联生成终端 是一款深度结合了尖端 NLP 语言模型 (ModelScope PALM) 与 中国皇家建筑美学 的交互式 Web 应用。我们彻底抛弃了繁琐的控件,将生成过程包装成一场“开门见喜”的仪式,为您呈现极具视觉冲击力的毛笔艺术对联。

看NSIS的说明中关于System的部分


D.3 Calling an external DLL using the System.dll plug-in

Some install processes are required to call functions contained inside third party DLLs. A prime example of this is when installing a Palm(TM) conduit.

Some background about System.dll
The System.dll plug-in (by Brainsucker) enables calling of external DLLs by providing the 'Call' function. There are a number of other functions provided by System.dll, but they will not be covered here. For more details about the other functions, lock the doors, take the phone off the hook, screw your head on *real* tight and head on over to the System readme.

Data Types
System.dll recognises the following data types:

  • v - void (generally for return)
  • i - int (includes char, byte, short, handles, pointers and so on)
  • l - long & large integer (known as int64)
  • t - text, string (LPCSTR, pointer to first character)
  • b - boolean (needs/returns 'true':'false') - by the fact this type is senseless -> usual integer can be used ('0':'1')
  • k - callback. See Callback section in system.html.
  • * - pointer specifier -> the proc needs the pointer to type, affects next char (parameter) [ex: '*i' - pointer to int]

Mapping System.dll variables to NSIS script variables
There's not much point in being able to call an external function if you can't get any data back. System.dll maps function variables to NSIS script variables in the following way:

NSIS $0..$9 become System.dll r0..r9 NSIS $R0..$R9 become System.dll r10..r19

Each parameter is specified by type, input and output. To skip input or output use a dot. Examples:

String (pointer to a characters array), input is 'happy calling':

t 'happy calling'

String (pointer to a characters array), input is taken from $5 and changes to the array made by the call are saved into $R8:

t r5R8

Pointer to an integer, value taken from $1 and put into $2:

*i r1r2

Pointer to a 64-bit integer, output pushed on stack, no input:

*l .s

Using System.dll::Call To call a function in a third party DLL, the Call function is used like this:

System::Call 'YourDllName::YourDllFunction(i, *i, t) i(r0, .r1, r2) .r3'

The '(r0, .r1, r2) .r3' section at the end are the parameters that are passed between your DLL and your NSIS script. As can be seen in this parameters list type and input/output can be seperated. Each block of "(parms list) return value" overrides and/or adds to the last one. In this case, the first block specifies the types and the second specifies input and output.

Before starting to code the NSIS script
Before you start to code any NSIS code, you need to know the full prototype of the function you are going to call. For the purposes of this example, we will use the 'CmGetHotSyncExecPath' function from the Palm 'CondMgr.dll'. This function is used to return the full path of 'HotSync.exe'.

Function Definition

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

where

  • pPath is a pointer to a character buffer. Upon return, this is the path & file name of the installed HotSync manager.
  • piSize is a pointer to an integer that specifies the size (in TCHAR's), of the buffer referenced by the pPath parameter.

return values:

  • 0: No error
  • -1: A non-specific error occurred
  • ERR_REGISTRY_ACCESS(-1006):Unable to access the Palm configuration entries
  • ERR_BUFFER_TOO_SMALL(-1010): The buffer is too small to hold the requested information
  • ERR_INVALID_POINTER(-1013):The specified pointer is not a valid pointer

Also, if the buffer is too small the value in *int is the size (in TCHARs) that the buffer should be.

This function definition maps to the following System.dll definition:

CmGetHotSyncExecPath(t, *i) i

i.e. It takes a text variable, a pointer to int, and returns an int value.

Using the external dll function
Now that we've sorted out what the function does, and how it maps to the System.dll format, we can use the function in a NSIS script.

First, you have to change the output directory to that where the DLL you want to use is. It may also work if the DLL is on the system path, but this hasn't been tested.

The following code fragment will install 'condmgr.dll' to a temporary directory, execute the CmGetHotSyncExecPath function and display returned data. Save this script

; **** snip ****
Function loadDll

  SetOutPath $TEMP\eInspect             ; create temp directory
  File bin\CondMgr.dll                  ; copy dll there
  StrCpy $1 ${NSIS_MAX_STRLEN}          ; assign memory to $0
  System::Call 'CondMgr::CmGetHotSyncExecPath(t, *i) i(.r0, r1r1).r2'
  DetailPrint 'Path: "$0"'
  DetailPrint "Path length: $1"
  DetailPrint "Return value: $2"

FunctionEnd
; **** snip ****

and this function produces the following output in the 'details' page:

Output folder: c:\windows\TEMP\eInspect
Extract: CondMgr.dll
Path: "C:\Dave\palm\Hotsync.exe"
Path length: 24
Return value: 0

Written by djc


总结

) dll的到处函数用extern "C" 形式的,不加WINAPI貌似不会出错,用def或者_declspc命令好像都行

)如果想调用后就卸载dll,注意参数 ? u

Function un.MyRemoveData
SetOutPath $INSTDIR
StrCpy $1 ${NSIS_MAX_STRLEN}
System::Call 'MiPlugin4NSIS::MiPIGetDataPath(t, *i) i(.r0, r1r1).r2 ? u'
IntCmp $2 0 +1 skiprmdir
RMDir /r "$0"
skiprmdir:
FunctionEnd
 'MiPlugin4NSIS::MiPIGetDataPath(t, *i) i(.r0, r1r1).r2 ? u'

 'MiPlugin4NSIS::MiPIGetDataPath(t, *i) i(.r0, r1r1).r2 ? u'

的解释

调用函数$INSTDIR目录中的MiPlugin4NSIS.dll的导出函数MiPIGetDataPath,函数参数类型为t(字符串), *i(int*),.r0(输出参数,放入$0中),r1r1(第二个参数为输入输出参数,已经放在了$1中),.r2(函数调用返回值放入$2中),? u(调用完成后立即卸载dll)

) 关于参数中的字符串。。。有人说是char*的,但是我的NSIS为Unicode版本的,经过测试字符串类型为wchar_t*。。。非Unicode版本为啥还需要测试


您可能感兴趣的与本文相关的镜像

🐎 乙巳马年 · 皇城大门春联生成终端W

🐎 乙巳马年 · 皇城大门春联生成终端W

AI应用
文本生成
PALM

乙巳马年 · 皇城大门春联生成终端 是一款深度结合了尖端 NLP 语言模型 (ModelScope PALM) 与 中国皇家建筑美学 的交互式 Web 应用。我们彻底抛弃了繁琐的控件,将生成过程包装成一场“开门见喜”的仪式,为您呈现极具视觉冲击力的毛笔艺术对联。

源码下载地址: https://pan.quark.cn/s/a4b39357ea24 【运算单元构造实验报告】运算单元是计算机硬件系统中的关键构成部分,主要承担执行算术运算和逻辑运算的任务。在本次实验中,我们着重探讨了带有累加器的运算单元的设计,涵盖了溢出识别、有符号数值与无符号数值运算的差异性,以及采用补码方式进行的加法与减法运算的实现机制。 一、实验目标 1. 掌握运算单元的基本构造,理解带有累加器的运算单元的具体实现途径。 2. 学习并领会溢出检测的机制,能够设计并构建溢出检测电路,用以判定运算结果是否超出了数据类型的表示范畴。 3. 明辨有符号数值和无符号数值运算的不同特性,把握它们在运算过程中各自的处理方法。 4. 熟练掌握基于补码方式的加法与减法运算的执行,理解补码形式下的溢出判定准则。 5. 熟悉运算单元内部的数据传输路线,明晰数据在运算过程中的流转路径。 6. 设计一个能够支持有符号数值与无符号数值运算、补码加法/减法运算以及有符号数值溢出检测的运算单元电路。 二、实验仪器 采用JZYL—Ⅱ型计算机组成原理实验装置,配备2片74181运算单元芯片作为算术逻辑单元(ALU),2片74LS373用作八位D型锁存器,并辅以一些基础门电路和多路选择器来完成电路设计。 三、实验内容 1. 运用片74181构建一个8位运算单元,负责处理数据的高4位与低4位。 2. 设计并实现溢出检测电路,确保在有符号数值与无符号数值的加法运算中均能准确识别溢出状况。 3. 通过74LS373增加累加器功能,使运算结果得以保存。 4. 将所有设计整合,利用多路选择器来支持有符号数值与无符号数值的加法/减法运算。 四、实验电路 1. 8位运算单元由2片74181构成,通过控制...
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值