Archive: external DLL


external DLL
OK. this is a little hard to explain.

i have a custom page with 2 textbox. (from an .ini file)
1. the user enters a code in every one of them.
2. when next button is pressed:
3. the content of the both textbox is stored in variables or constants (?)
4. i must use this variables/constants to validate the codes. something like this, with a function:

function ValidateSerialNumber(myFile, User, Orgn, , , , PrivateKey, Serial: String): Boolean;

and then to call the DLL. i found in documentation that is something like this:

System::Call 'YourDllName::YourDllFunction(i, *i, t) i(.r0, r1, .r2) .r3'

5. if the codes are not correct the user is not allowed to move on.

if you have any ideas how to do this, tell me, please,

becuase i have no idea.:igor:


You can use the System plug-in to call your DLL, but maybe it's easier to create a NSIS plug-in.


sorry! you lost me...i am reding the system readme, but noy understanding a thing.

let's do this step by step:
how do i take the content of the both textbox and store them in variables or constants (?)


Try this example
Note that you must implement a dll ( for this example is "MyExternDLL.dll" with export "ValidateUser") and store the dll in NSISDIR\Plugins

Just use some source code from other plugin (NSISDIR\Contrib) so that you can start and change the code

You can debug easily if using VC++, just change project settings and choose your output setup.exe as "Executable for debug session"

Good luck
Ramon


A better way would be checking the leave function. See the example in Contrib\InstallOptions\test.nsi. It does exactly this.

As for the DLL, you didn't write it right? Do you have the source code for it? If you don't then you'll need to call it using System. Show me the function prototype and I'll help you writing a System::Call line. If you do, then you might want to consider compiling a NSIS plug-in version so it'll be easier to call.


thanks, again, for helping,

ok. i checked the "Contrib\InstallOptions\test.nsi" script. i have now the codes entered by the user in 2 variables (from the textboxes).

as for the DLL, i did not write it, i do not have the source code.
i don't know what you mean by "function prototype". if you are talking about what i made so far, no problem. but until now i have only a custom page with 2 textbox. (btw: one textbox, two textboxes ?, my english is not so good)

"function ValidateSerialNumber(myFile, User, Orgn, , , , PrivateKey, Serial: String): Boolean;", this is taken from the DLL readme.

myFile - is encrypted file (i have it) - OK.
user and orgn - user name, organization name (automatic inside the installer). - OK.
PrivateKey and Serial - the 2 textboxes. - OK.

all i have to do now is to call the DLL with all this parameters. the DLL returns true or false. if its false, the user will not be allowed to pass.

to compile a NSIS plugin version? no problem. if it works...


"function ValidateSerialNumber(myFile, User, Orgn, , , , PrivateKey, Serial: String): Boolean;" is the function prototype, but it doesn't make sense to me. Is another line that looks like that in the readme? Something with char* or LPSTR? Will you be able to attach the readme or mail it to me privately?

If you haven't written the DLL and you don't have the source you can't compile it as a NSIS plug-in.


hello!

after a few hours spent in "The Archive" and readme files, it's a little better. i can say i'm begining to understand what you're talking about.

yes, there were some stuff there. i will attach it.


According to this program's readme (download from http://www.mjfreelancing.com/) the call should be:

System::Call "ISID::ValidateSerialNumber(t, t, t, t, t, t, t, t) i ('keypath', 'user', 'orgn', '', '', '', 'user private key', 'user serial') .s"
Pop $0

$0 contains the result.

Make sure the DLL is somewhere System.dll can find it (the current directory set by SetOutPath for example). The best way would probably be extracting the DLL to $PLUGINSDIR and using SetOutPath $PLUGINSDIR.


i tried to make it work, but no. sorry

i will attach my script, but i cannot attach the DLL, is about 1.3MB. download it from - see above.

my condition after the DLL sytem call is not good, if you do not enter the right codes you cannot exit the program. even if you press back or cancel.

and even in the System::call line i did something wrong. the DLL always returns "0" or "false" - if i change from "i" (int) to b(boolean). and the codes are good. i checked. too make it easy i enetered the codes in the ini file.

here is the script.


The wrong thing in the DLL function call is just the order of the last two arguments. Unlock code should come after the private key.

For the user to be able to exit the installer you must use the leave function of the page. The leave function is only called when the user clicks next. If the DLL returns false you should call Abort to not allow the user to continue to the next page.

Leave callback funciton is not available in b3 but only in the latest CVS version. Use NSIS Update to get it. If you don't want the latest CVS version you should use something like the code in this page:

http://nsis.sourceforge.net/archive/....php?pageid=87

You will also notice the $PLUGINSDIR is not deleted. This seems to be a feature of Systemd.dll I have never noticed. It doesn't free DLLs. To make sure the DLL is deleted you can use this trick:

SetDetailsPrint none
RegDLL $PLUGINSDIR\ISID.dll "a function name that doesn't exist"
SetDetailsPrint both


This will make NSIS load the DLL and then unload it completely.

sorry. my mistake.
i inverted the last 2 arguments (.r3, .r4 is now .r4, .r3) and still the DLL response is "0" or "false".

i don't get it.


i changed my script to use the leave function. (i think)

but now i get this :

install function ... not referenced - zeroing code ...

how do i use "abort" ?

is this correct ? : StrCmp $0 "false" Abort.
i'll answer that. no. then how ?

my script..


You should be using:
Page custom "Protect" "Validate" "Title"

Where "Title" is the title of the custom page (e.g. " - Enter Codes")

-Stu


Remove the dots and it should work:

System::Call "ISID::ValidateSerialNumber(t, t, t, t, t, t, t, t) i ('$PLUGINSDIR\OwD.iky', r1, r2, '', '', '', r4, r3) .s"


thanks for helping. here is the working script. feel free to use it.


That looks pretty good.

Can anyone think of any way of exposing that DLL to IIS / ASP environment so that the customer can be emailed their registration code automatically after purchasing the download online? (based on the details they enter)

Cheers

R


If everything else fails you can always write a little NSIS script that will call the DLL, and write the result into a file which the ASP code will read. Use a silent "installer" to do the job.