Archive: How to make DLL Plugins


How to make DLL Plugins
Hello All,

I'm using NSIS for creating a setup.

After reading the documents, I'm still not clear how to
call any function in dll from .nsi file.

If anybody having example of DLL Plugin please do mail me
at ppp_pras@yahoo.com


Put your DLL in the Plugins directory or call PluginDir with the directory in which this plugin resides and then use DllNameWithOut.DllExtension::FunctionName.


Further Problem : kichik
Hello kichik,

Your reply helped me a lot.

But now I am not getting how to pass the Arguments to the function.
and get return datatypes.

Please help me.


Passing and getting parameters to and from the plug-in can be done in two ways. The first is using the NSIS stack (push and pop) the second is through the NSIS variables. You can access both from the plug-in using pushstring, popstring, getuservariable and setuservariable (all defined in ExDLL.h in Contrib\ExDLL).

The preferred way is using the NSIS stack. To pass arguments to the plug-in use:

PluginName::Function arg1 arg2 arg3

The arguments will be pushed to the stack from right to left. The first time you call popstring in the plug-in you will get arg3 (you can push as many arguments as you want as long as there is enough memory ;)).

To get the "return value" of the plug-in (preferably strings pushed by the plug-in) use Pop in NSIS:

PluginName::Function arg1 arg2 arg3
Pop $0

The only data type NSIS knows is a string. If you want to convert the strings NSIS pushes on the stack you will have to use your own functions. You can find some in the other plug-ins written.

Please reply to this thread next time instead of opening another one.


Hi All,

Kichik you told me how to call any function from pluginn dll.

See I'm trying to execute following code.
After Testing Installation. It give error and says "error log is being written"

1) Where is the error log?

I'm trying to execute following code

StrCpy $R1 "LFcl"
StrCpy $R2 "CeloxisCond"
StrCpy $R3 "C:\\CDK402a\\Common\\Bin\\C4.02\\jsync13.dll"
CondMgr::CmInstallCreator $R1 "1"
CondMgr::CmSetCreatorName $R1 $R3
CondMgr::CmSetCreatorDirectory $R1 $R2
CondMgr::CmSetCreatorFile $R1 $R2
CondMgr::CmSetCreatorPriority $R1 "1"

But it's not working

Please help me in this regards.


NSIS has no such error message ("error log is being written"). Are you sure it comes from NSIS and not your plug-in? Are you sure you copied it right?
Escaping the back-slashes in $R3 which is not needed in NSIS. I don't see anything wrong in this piece of code but that.


StrCpy $R1 "LFcl"
CondMgr::CmInstallCreator $R1 1

I can Compile NSIS script containing above lines. So there is no doubt that the file is there or not. Now when I click on Test Installer it runs my Executable(Installer). And at the point where I called that function it gives error
as follows:
-------------------------------------
Installer.exe has generated errors and will be closed by Windows. You will need to restart the program.

An error log is being created.

------------------------------------
Please guide me how to debug the error in such situation.


If the error occurs when you call your plug-in the problem is in your plug-in. To make sure put a message box before and after the call to the plug-in. If the first one shows but the second doesn't it's your plug-in for sure. To debug your plug-in compile it in debug mode and debug... As I don't have the plug-in source I can't help you much there...


HsCheckApiStatus prototype is :
long WINAPI HsCheckApiStatus (void);

HSAPI::HsCheckApiStatus
Pop $0
IntCmp $0 HSAPI::ERROR_HSAPI_HOTSYNC_NOT_FOUND hotsync_not_running
IntCmp $0 HSAPI::ERROR_HSAPI_FAILURE hotsync_api_failure

MessageBox MB_OK "HOT SYNC.$0"
return

hotsync_not_running:
MessageBox MB_OK "HOT SYNC NOT RUNNING. PLEASE START HOTSYNC."
return
hotsync_api_failure:
MessageBox MB_OK "HOT SYNC API FAILURE"
return
-----------------------------------------------------------
This is my api and this is how I have written code.
Problem is it always goes to label
"HOT SYNC NOT RUNNING. PLEASE START HOTSYNC."

How to deal with return types that are long or int?


I'm writting a code in NSIS which deals with DLL plugins.
The function has two arguments: the first one is an integer and the second is a char *.
How does one pass Integer and String to that function?

The function which I call returns an integer.
How to get this integer value in variable? Pop documentation says it pops of a string.

Can I use the return value (after getting it as described above) in IntCmp?


The prototype you used is wrong. The right prototype as mentioned in the ExDLL example is:
void __declspec(dllexport) myFunction(HWND hwndParent, int string_size, char *variables, stack_t **stacktop);

Data types:

The only data type NSIS knows is a string. If you want to convert the strings NSIS pushes on the stack you will have to use your own functions. You can find some in the other plug-ins written.
Same goes for what NSIS accepts... The only data type NSIS knows is strings which means you will have to convert your output to a string and push it on the stack.

Hello kichik,

Do you know which DLLs provide such fuctions. Please give me names of such DLL files.


- contrib/nsexec.c uses wsprintf to convert ints to strings
- contrib/nsexec.c implements my_atoi to convert strings to ints
- contrib/advsplash.c uses wsprintf to convert ints to strings
- contrib/advsplash.c implements myatoi to convert strings to ints
- contrib/langdll.c implements myatoi to convert strings to ints
- contrib/nsisdl/util.cpp implements my_atoi to convert strings to ints (and also implements mini_memset and mini_memcpy)
- contrib/splash.c converts strings to ints using inline code (line 70)
- contrib/splash.c converts ints to strings using wsprintf
- contrib/system/source/plugin.c implements myitao, myitoa64, popint, pushint and copymem

That should give you some idea what KiCHiK was on about.