Archive: How to get a value from DLL using System::Call


How to get a value from DLL using System::Call
I want to call a function in a DLL, say MyDLLName.dll, using System::Call


BOOL __stdcall FunctionW(
IN LPCWSTR FileName1,
IN LPCWSTR FileName2,
IN LPCWSTR FileName3,
IN LPCWSTR FileName4,
IN LPCWSTR Identifier,
OUT LPBOOL MustReboot
);

How does this work?

I've converted this to
 
System::Call "MyDLLName::FunctionW(t $INSTDIR\file1.sys, t $INSTDIR\file2.sys, t $INSTDIR\file3.sys, t $INSTDIR\file4.sys, t 'ANYID', b) b";


Question 1: Does that seem right?

Question 2: Also how do I get the return boolean value so I can use it (to reboot the computer or show a messagebox).


Thanks for looking!

LPCWSTR is wide string. Use w instead of t. For boolean, use i.


Thanks for catching that! On reading 'Calling an external DLL using the System.dll plugin' on the wiki, I thought it didn't support w.

Now I need the return values from this function, but I can't make head or tail of the ;(.r0 .r1 .r2 .r3 .r4 .r5 .r6) .r7" type format.

Is there any simple documentation on how to get return values from a function?


There's the System plugin documentation.

You want i.s on the end instead of b then the return value will be pushed onto the stack (or you can use i.R0 ($R0) or i.r0 ($0) among others to put the return value into the respective NSIS variables).

Stu


Ah, I want two values here.
Firstly the function itself returns a boolean 'success/failure' result, and secondly the last argument returns a long boolean 'reboot needed/not needed' result.

So you mean it should be like


System::Call "MyDLLName::FunctionW(w $INSTDIR\file1.sys, w $INSTDIR\file2.sys, w $INSTDIR\file3.sys, w $INSTDIR\file4.sys, w 'ANYID', i.r0) i.r1";


${If} $0 == 1
MessageBox MB_OK "Reboot needed"
${Else}
MessageBox MB_OK "Reboot not needed"
${EndIf}

${If} $1 == 1
MessageBox MB_OK "Function returned one."
${Else}
MessageBox MB_OK "Function returned zero."
${EndIf}

You need to wrap strings in double quotes (""). Use '' for the outer quotes.

Stu


A better idea would be pushing them on the stack or passing them through registers. This way you won't get any parsing surprises.