Skip to content
⌘ NSIS Forum Archive

NSIS - calling dll function

9 posts

Tracer1808#

NSIS - calling dll function

Hi!

I saw the general documentation regarding this subject, but to be honest I still don't understand how to do it.

So, let's say I have the following dll function written in C++ Builder (mydll.dll):

extern "C" __declspec(dllexport) __stdcall int myFunc(char* a, char* b, char* c);
How do I call this dll function from NSIS script? Return value should be stored somewhere so I can later check it.
Anders#
Did you look at the examples at the bottom?

Try
System:: Call 'yourdll::myFunc(m "foo",m "bar", m "baz")i.r0'
DetailPrint $0
If it doesn't work, make sure that the function export is named correctly without decorations...
JasonFriday13#
For that example above, you would have to use the system plugin.
System::Call "mydll.dll::myFunc(m $a, m $b, m $c) i .r0" ; $0 contains the returned variable.
If you are talking about nsis plugins, you can't "pass" variables through it's parameter list. You have to use a set parameter list, and then pop your arguments off the stack. To return a variable use push. You can use multiple pushes to return multiple variables. This way you can call an nsis plugin straight from the script like so:
mydll::myFunc $0 $1 $2
pop $3 ; returned value
There's a basic example (ExDLL) in the nsis/contrib/ExDLL folder about the requirements for an nsis plugin to work correctly.

[edit] Anders you ninja 😁
Anders#
Originally Posted by JasonFriday13 View Post
System::Call "mydll.dll::myFunc(m $a, m $b, m $c) i .r0" ; $0 contains the returned variable.
Please quote string parameters unless you are certain they don't contain spaces or commas! The only exception is the built-in registers and variables that have system plugin aliases; t r0 etc.
JasonFriday13#
True, thanks. I'm a bit rusty on my nsis scripting, I haven't written an nsis script in at least a year (been looking at too much C code 🙄).
Tracer1808#
My dll function is connecting to online db server. The problem is that user may have internet connection problems or my server may be down for some reason. In those cases my NSIS setup file (exe) crashes since dll function generates exception.

It is possible to use try-catch in NSIS script so when I call dll function to check if any exceptions happened?
Anders#
Originally Posted by Tracer1808 View Post
It is possible to use try-catch in NSIS script so when I call dll function to check if any exceptions happened?
Nope, neither C++ nor SEH exceptions are supported...
Tracer1808#
Too bad...

Now I also have another problem. How to pass boolean value to my dll function? Function takes bool type as a parameter.

Edit: passed it as integer