Archive: Calling external DLL's


Calling external DLL's
I am learning how to write dll's and call them with NSIS.

When I try the following I get an empty return value.


....
ReserveFile "${NSISDIR}\Plugins\RGRegistration.dll"
....

Function .onInit
StrCpy $r1 "RODRIGO"
System::Call 'RGRegistration::Test(t) t(r1).r0'
#Pop $r0
MessageBox MB_OK "$r0"
FunctionEnd

I am trying to pass a string value, and get a string value back.

This is the dll function :

_declspec(dllexport) LPCTSTR Test(LPCTSTR name)
{
return "Got it!";
}

What am I doing wrong?


I think you are mixing up the method of using the System.dll and using other plug-ins.

RGRegistration::Test $parameters

Take a look at ${NSISDIR}\Examples\AdvSplash\Example.nsi or one of the other plugin example scripts. There are also plenty of other plug-ins out there that include the source and example usage.

You must also extract the DLL. Reserving it is not enough. Use:

InitPluginsDir
SetOutPath $PLUGINSDIR
File "${NSISDIR}\Plugins\RGRegistration.dll"
System::Call 'RGRegistration::Test(t) t(r1).r0'
If you want to call it as dienjd suggested, you'd have to change the parameters your function accepts. Take a look at Contrib\ExDLL in the source package.

oops, didn't know you could do that, but it makes sense.

Is there any advantage to using System.dll to call your plug-in? Seems like the call is cleaner when you call a plug-in directly, and you'd be bundling System.dll unneccesarily if you weren't making other system calls.