j27lee
31st October 2003 23:05 UTC
Help with dlls
Hi all,
I'm trying to call an external dll to validate a CD Key and am not sure the dll is even getting called. Is there a way to test this?
The dll returns a 1 if the key is valid and a 0 if it is invalid. Here's the section that deals with this.
SetOutPath $INSTDIR\dll
File bin\KeyCheck.dll
StrCpy $0 "1234567812345678"
MessageBox MB_OK "CDKEY: $0"
System::Call "KeyCheck::isCDKeyValid(t r0) i r1"
MessageBox MB_OK "RETURN_CODE after: $1"
If I run this, I get a MB with "RETURN_CODE: ". So I'm not sure if the dll is even being called. The interface is this:
INTERFACE bool isCDKeyValid(const char * cdKey);
any help would be appreciated!
Thanks,
James
kichik
31st October 2003 23:18 UTC
You forgot the dot before r1. Use:
System::Call "KeyCheck::isCDKeyValid(t r0) i .r1"
That dot tells System.dll to ignore the input for the return value (which you should always do beacuse there is no need for input for something that doesn't take any) and treat $1 as the output for the return value.
BTW, why not create a NSIS plug-in? It would be much easier to use. There are template for more than one programming language in Contrib\ExDLL.
j27lee
31st October 2003 23:33 UTC
Thanks kichik,
When I add the dot before r1, I get "RETURN_CODE after: error". There is one parameter (r0) unless I'm using this wrong. I noticed a change in syntax from "System::Call "CondMgr::isCDKeyValid(t) i(.r0) .r1" to the current syntax. Am I more off base than I think?
Is there any way to determine the error? or is that a function of the boolean type?
As for plugins, I haven't tried, but figured I would try with the dll as it existed. How would the implementation differ? Can they still be used as dlls from other apps?
Thanks,
james
kichik
31st October 2003 23:58 UTC
If you are using NSIS b3 try adding another SetOutPath line (there is a bug with the current directory setting code). If you are using the latest CVS version, make sure the exported name is exactly the one used in the script. Use Dependency Walker to make sure.
There is no difference between (t)i (.r0) .r1 and (t .r0) i .r1. It's just System.dll allowing you to override the parameters with another set. It's useful if one wants to define a function using !define. For Example:
!define MyFunc "MyDLL::MyFunc (t 'default string', i, i 4)"
System::Call "${MyFunc} ('another string', 3, )"
As for the NSIS plug-in, you will be able to keep the other function. You will just need to add another function that NSIS can call that will be a wrapper for the original function.
j27lee
3rd November 2003 18:41 UTC
Thanks for your help kichik... i think i understand the whole thing a bit better now. In my case, turns out the dll was to blame.
Thanks again,
James