Archive: Help with Dll function usage


Help with Dll function usage
  Hi,

I've been trying NSIS for a couple of days now.

I'm creating a serial validation page with 4 fields 5 chars each. I've read the forums, the read-me's for InstallOptions and System, and some examples in the WiKi, and still cant put this to work!

I'd thank any help at this.

Here are my two functions, along with the initialization code.

!define Key1 $R1     ; Serial Part 1

>!define Key2 $R2 ; Serial Part 2
>!define Key3 $R3 ; Serial Part 3
>!define Key4 $R4 ; Serial Part 4

>; Things that need to be extracted on startup (keep these lines before ; any File command!)
; UseReserveFile for your own InstallOptions INI files too!
>ReserveFile "wndSerial.ini"
>ReserveFile "files\other\ValidateSN.dll"
>ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll"

>Function SetCustom
;Display the InstallOptions dialog
Push${Key1}
Push ${Key2}
Push ${Key3}
Push ${Key4}
Push $R0
InstallOptions::dialog "$PLUGINSDIR\wndSerial.ini"
Pop $R0
Pop${Key4}
Pop ${Key3}
Pop ${Key2}
Pop ${Key1}
>FunctionEnd

>Function ValidateCustom
FlushINI "$PLUGINSDIR\wndSerial.ini"

; Serial number inits
!insertmacro MUI_INSTALLOPTIONS_READ ${Key1} "$PLUGINSDIR\wndSerial.ini" "Field 2" "State"
!insertmacro MUI_INSTALLOPTIONS_READ ${Key2} "$PLUGINSDIR\wndSerial.ini" "Field 3" "State"
!insertmacro MUI_INSTALLOPTIONS_READ ${Key3} "$PLUGINSDIR\wndSerial.ini" "Field 4" "State"
!insertmacro MUI_INSTALLOPTIONS_READ ${Key4} "$PLUGINSDIR\wndSerial.ini" "Field 5" "State"

SetPluginUnload alwaysoff

; Call the function to validate the netmamma serial number
System::Call "user32::MessageBox(i $HWNDPARENT, t .r1, t 'Test', i 0)"

System::Call "$PLUGINSDIR\ValidateSN.dll::ValidateSN (t,t,t,t)i (.${Key1},.${Key2},.${Key3},.${Key4}).r0"

; --- get output
Pop$0
StrCmp$0 "1" serial_ok serial_wrong

serial_ok:
MessageBox MB_OK "OK-OK-OK-OK"
Goto done

serial_wrong:
MessageBox MB_OK "$0"
Abort

done:
; Continue installation
MessageBox MB_OK "$0"

>FunctionEnd
>
Can anyone help out with this, any help will be greatly appreciated! :(

Thanks in advance,
smoura

The thing is that I'm not being able to get the values typed in the wndSerial.ini page back to the variables... :P


From a quick look on your script:
you use defines to get values, this is not correct.
You must use variables to get the values from INI fields.
e.g.
change this:
!insertmacro MUI_INSTALLOPTIONS_READ ${Key1} "$PLUGINSDIRwndSerial.ini" "Field 2" "State"
to this:
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "$PLUGINSDIRwndSerial.ini" "Field 2" "State"


Thanks for the fast reply ;)

I've replaced Has you've said the 4 instructions on my code, though it continues not to extract the data from the fields.

Here's the changes I've made to the above source:



Serial number inits

>!insertmacro MUI_INSTALLOPTIONS_READ $R1 "$PLUGINSDIR\wndSerial.ini" "Field 2" "State"
>!insertmacro MUI_INSTALLOPTIONS_READ $R2 "$PLUGINSDIR\wndSerial.ini" "Field 3" "State"
>!insertmacro MUI_INSTALLOPTIONS_READ $R3 "$PLUGINSDIR\wndSerial.ini" "Field 4" "State"
>!insertmacro MUI_INSTALLOPTIONS_READ $R4 "$PLUGINSDIR\wndSerial.ini" "Field 5" "State"

>; Call the function to validate the serial number
MessageBox MB_OK "$R1"
I suppose that this message box should prompt the first field in the Serial number dialog. At least this is what I'm trying to do :P

replace this:
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "$PLUGINSDIRwndSerial.ini" "Field 2" "State"
with this:
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "$PLUGINSDIR\wndSerial.ini" "Field 2" "State"

wndSerial.ini must be the exact name of the IO ini file you have extracted on $PLUGINSDIR

Just now I noticed you're making the same mistake in the whole script.


There is a missing backslash almost everywhere on your script :-)
When I shaw it first time I focused to to the defines.
You should read the script line by line and add the missing backslashes :-)


:) the backslashes are in the code, it seems that when I copy the code from the editor to the post form it removes the backslashes... :P


I don't know if the system call to the plugin dll is correct thus working.
Besides that if the INI file extraction is right and your custom page appears normally, this code should read the values from ini fields:
Function ValidateCustom
ReadIniStr $R1 '$PLUGINSDIR\wndSerial.ini' 'Field 2' 'State'
messagebox mb_ok "$R1"
...................


I also noticed some code that is not particularly 'clean':

InstallOptions::dialog "$PLUGINSDIRwndSerial.ini"
Pop $R0

Should be:

InstallOptions::dialog "$PLUGINSDIRwndSerial.ini"
Pop $R0
Pop $R0

This just erases the return value from InstallOptions::dialog (it is pushed onto the stack).

[edit]I also just noticed this: Why are you calling a messagebox function with the System plugin? NSIS already has a messagebox function (you probably aready know this).[/edit]


Thanks all for the replys.

Red Wine:

The custom page does indeed appear absolutly normal with the 4 fields to fill. I'm just not being able to get the values back from the fields (the code you've placed is exacly what I'm trying to put to work here).

JasonFriday13:

Thanks for the note on the Pop, I've put the other Pop instruction on the code still, cant get anything from the form.
Has for the message boxes their only for test purposes, to see the value in the first one and then check if I can use the system plugin correctly, hence the real purpose for this issue is serial validation through an auxiliar dll.

I'll try to create a clean install to sharpen my skills.

All sugestions will be greatly appreciated ;)


Well I've managed to get the values back from the custom page by using the ReadINIStr instead of the MUI macro, though the problem was that Pop that Jason said, since before using the macro I was using the ReadINIStr to read...

I'll now try to see why the dll doesn't get called, any help on this would be greatly apreciated! :)

I suppose that this:

System::Call "user32::MessageBox (i $HWNDPARENT, t r11, t 'Test', i 0)" 
should show a message box with the $R1 variable of NSIS script, I'm not getting any message at all :P.

I guess you want to pop up a messagebox for debug...
Anyway try this:
MessageBox MB_OK|MB_ICONINFORMATION "$$R1==$R1"
Native message boxes work perfectly, you may want to refer to NSIS documentation for details.


Dammm :D:D:D it's working. Thanks all for the replys.

The problem with the call to the dll function was that I used the .dll in the System::Call function, rather then using only the DLL name. The final line looks like this:

System::Call "$PLUGINSDIR\\ValidateSN::ValidateSN(t r11, t r12,t r13,t r14)i r0" 

Thanks RedWine! But I was using the Native Message box to try an easier function than my on dll with the System plugin. :)