如何在NSIS中调用DLL

kevin_darkelf 2006-12-08 08:32:14
在NSIS中调用DLL中的函数,执行报错,请懂的达人看看~`谢谢

; install the NetCtrol driver
Push true
Push "$INSTDIR\SecSPI.dll"
CallInstDLL $INSTDIR\NetRegister.dll NetRegister

NetRegister原型: int NetRegister(bool bInstall, char * pPath);

另一点是如何获得函数执行的返回值 在NSIS中~`
...全文
1913 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pomelowu 2006-12-12
  • 打赏
  • 举报
回复
呵呵。。。其实就是那个?麻烦。。。
palmax 2006-12-12
  • 打赏
  • 举报
回复
其实system::call 是调用nsis的plugins目录下system.dll的导出函数call,通过这个你可以调用系统中的其他函数
用法我还没有搞的很透,基本语法是这样的:
System::Call "dll文件全路径::dll的导出函数名(参数类型 参数,....) 返回值 ? 调用方式"
其中那个?我一直没搞明白,是照例子做的
那帮助文件的例子来说,帮助文件里的参数写法和我的不大一样:
--------------------------------------------------------------------------------
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"

; last plug-in call must not have /NOUNLOAD so NSIS will be able to delete
; the temporary DLL

SetPluginUnload manual
; do nothing (but let the installer unload the System dll)
System::Free 0
FunctionEnd
----------------------------------------------------------------------------------
看这行:
System::Call 'CondMgr::CmGetHotSyncExecPath(t, *i) i(.r0, r1r1).r2'
表示plugins目录下有个CondMgr.dll,这个dll有个导出函数CmGetHotSyncExecPath,有两个参数,
第一个是char*(out),第二个是int(in,out),即r0为输入参数,r1既为输入又为输出参数,返回值为int,放在r2里
pomelowu 2006-12-12
  • 打赏
  • 举报
回复
CallInstDLL的确是NSIS的函数,不过是用来调用NSIS里插件DLL的函数的,如果不是插件DLL,还是用System::Call吧。

如果的确是CallInstDLL,那么你在调用之后紧接着Pop一个变量就好了,返回值也是通过堆栈传递的。

ps,palmax(南宫煌)能不能给我讲讲怎么用System::Call?它的用法我还真的没明白。。。
kevin_darkelf 2006-12-12
  • 打赏
  • 举报
回复
呵呵~``兄弟~刚问了一下朋友, CallInstDLL 是NSIS的函数, 要不然我怎么会去查这个帮助~```
palmax 2006-12-12
  • 打赏
  • 举报
回复
既然CallInstDLL是自己定义的函数,你直接 Call InstDLL 就好了
在InstDLL里,先 Exch 出你调用前 push 的参数到变量里,然后调用,举个例子:
Push $result
Call InstDLL
StrCmp $result "error" ....
................

Function InstDLL
Exch $R0
System::Call "$INSTDIR\yourdll.dll::fun_name(t $Param1) .R0 ? c"
Exch $R0
FunctionEnd
kevin_darkelf 2006-12-12
  • 打赏
  • 举报
回复
算了算了~`看来有必要重述一下为什么我会来问这个了 -____-~!
别人弄的,晚饭之前叫我用一下(接口是我写的),有什么问题回来给他说,有了问题我按他说的查了一下帮助,用的"CallInstDLL",就和例子差不多三,这本不是我的份内之事,也没要去专门为这看教程,只是在他回来之前好心帮问一下,结果说我好像是说吃白饭的一样~`
OK,就此打住,这里不是水池
Push "a parameter"
Push "another parameter"
CallInstDLL $INSTDIR\somedll.dll somefunction
palmax 2006-12-11
  • 打赏
  • 举报
回复
帮助文件里根本就不是你写的那样,说明你没看
即使帮助文件你没看,网上那么多教程也总看了吧,连个 System::Call 都不知道,还好意思说是按帮助文档弄的,下面把帮助文档的内容帖出来,大家做个见证:

------------------------------------------------------------------------------------
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, it is recommended to turn 'PluginUnload' off before making multiple calls to System.dll. According to Brainsucker (and others), this will speed up execution of the installer package.

Second, 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, display returned data and finally unload the System.dll plug-in. Save this script

; **** snip ****
SetPluginUnload alwaysoff

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"

; last plug-in call must not have /NOUNLOAD so NSIS will be able to delete
; the temporary DLL

SetPluginUnload manual
; do nothing (but let the installer unload the System dll)
System::Free 0
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

-----------------------------------------------------------------------------------
kevin_darkelf 2006-12-11
  • 打赏
  • 举报
回复
B4楼上的~`不要以为人人都是你想象中的那样
叫你在一晚上把本不是份内之事搞定,按帮助文档弄出来通过不了,向人请教有什么错~?
palmax 2006-12-08
  • 打赏
  • 举报
回复
对不看帮助文件的纯顶不回-_-

3,248

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧