Old 24th May 2015, 20:54   #1
Tracer1808
Junior Member
 
Join Date: May 2015
Posts: 6
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):

code:
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.
Tracer1808 is offline   Reply With Quote
Old 25th May 2015, 03:27   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Did you look at the examples at the bottom?

Try
Quote:
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...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 25th May 2015, 03:46   #3
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
For that example above, you would have to use the system plugin.
Quote:
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:
Quote:
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

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 25th May 2015, 06:58   #4
Tracer1808
Junior Member
 
Join Date: May 2015
Posts: 6
It works! Thanks!
Tracer1808 is offline   Reply With Quote
Old 25th May 2015, 14:36   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Quote:
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 27th May 2015, 00:15   #6
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
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 ).

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 30th May 2015, 21:20   #7
Tracer1808
Junior Member
 
Join Date: May 2015
Posts: 6
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?
Tracer1808 is offline   Reply With Quote
Old 31st May 2015, 00:07   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Quote:
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...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 31st May 2015, 08:47   #9
Tracer1808
Junior Member
 
Join Date: May 2015
Posts: 6
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
Tracer1808 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump