Old 23rd May 2006, 09:21   #1
smoura
Junior Member
 
Join Date: May 2006
Posts: 17
Question 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.

PHP 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!)
; Use 
ReserveFile 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 
$"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
smoura is offline   Reply With Quote
Old 23rd May 2006, 09:31   #2
smoura
Junior Member
 
Join Date: May 2006
Posts: 17
The thing is that I'm not being able to get the values typed in the wndSerial.ini page back to the variables... :P
smoura is offline   Reply With Quote
Old 23rd May 2006, 11:06   #3
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
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"

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 23rd May 2006, 12:53   #4
smoura
Junior Member
 
Join Date: May 2006
Posts: 17
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:


PHP Code:
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
smoura is offline   Reply With Quote
Old 23rd May 2006, 12:57   #5
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
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.

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 23rd May 2006, 13:05   #6
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
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 :-)

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 23rd May 2006, 13:16   #7
smoura
Junior Member
 
Join Date: May 2006
Posts: 17
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
smoura is offline   Reply With Quote
Old 23rd May 2006, 16:28   #8
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
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"
...................

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 23rd May 2006, 22:03   #9
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
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]

"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 24th May 2006, 08:06   #10
smoura
Junior Member
 
Join Date: May 2006
Posts: 17
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
smoura is offline   Reply With Quote
Old 24th May 2006, 10:17   #11
smoura
Junior Member
 
Join Date: May 2006
Posts: 17
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:
PHP Code:
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.
smoura is offline   Reply With Quote
Old 24th May 2006, 11:14   #12
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
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.

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 24th May 2006, 11:15   #13
smoura
Junior Member
 
Join Date: May 2006
Posts: 17
Dammm 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:

PHP Code:
System::Call "$PLUGINSDIR\\ValidateSN::ValidateSN(t r11, t r12,t r13,t r14)i r0" 
smoura is offline   Reply With Quote
Old 24th May 2006, 11:17   #14
smoura
Junior Member
 
Join Date: May 2006
Posts: 17
Thanks RedWine! But I was using the Native Message box to try an easier function than my on dll with the System plugin.
smoura 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