cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Nicolasb
Level 5

Serial number validation dll

Hi,
I want to create my own dll to validate the serial number entered in the CustomerInformation dialog. Where should I put the dll in the project (SUPPORTDIR?) and how do I call it through a custom action ?
I searched the website about this problem and I only found information related to InstallShield 2008 Express (here) and I did not found the field the authors refers to.
Thanks,
Labels (1)
0 Kudos
(17) Replies
gridman
Level 8

Since a DLL is really an assembly, then it may need to be placed in its own component (with nothing else in the component).

I think what you are saying would work. You would want to create an InstallScript custom action and first load the DLL, call the serial number validation function, then unload the DLL.

I think some people place a Validate button in the CustomerInformation dialog. When the user clicks the button, you have a DoAction behavior on the Validate button that calls the custom action. You would also attach a condition to the Next button that the user can't move forward until he has validated the serial number. You could do this by checking if a property has been set (your validate function would set the property if the validation has passed).
0 Kudos
Nicolasb
Level 5

Thanks, I've already implemented something to validate the serial number on the next button event. About the idea of putting the DLL in a component I'll try it, but how would I acces it at run-time ? The components are not copied to disk yet at this moment during the installation.
0 Kudos
gridman
Level 8

I don't understand your question.

If you put the DLL in a component, and attach no conditions to it (the component), and point the component destination to say [INSTALLDIR], then there is no reason why it wouldn't be copied to your target folder upon installation.
0 Kudos
Nicolasb
Level 5

The validation of the serial occurs before the files are copied to disk.
0 Kudos
gridman
Level 8

Pardon me, I made a mistake. What you said makes perfect sense.

So then, you are correct. You would need to place the DLL in the SupportFiles/Language Independent folder. That is where the files will be extracted to during the installation. Then in the custom action, you would build a path to the DLL using the SUPPORTDIR variable.

How about that?
0 Kudos
Nicolasb
Level 5

Ok Good! I should install the files in the SUPPORTDIR. That was my first question.

Now, the second part of my question. How may I call the DLL via a Custom Action ? I can launch a CA at the right moment during install, but I can't make that CA to launch a dll stored in SUPPORTDIR.
0 Kudos
gridman
Level 8

First I would probably create an InstallScript function in the InstallScript view. Call it something like ValidateSerialNumber. At this point you could make it an empty function. Just a frame so you could create the custom action.

Then create an InstallScript custom action that uses the ValidateSerialNumber function.

If you placed a Validate button in the CustomerInformation dialog, then you would need to go to the Dialogs view, expand the CustomerInformation dialog, click Behaviors, then click on the Validate button. Then create a DoAction event with the argument ValidateSerialNumber and a Condition of 1. So, when the user clicks the Validate button, the custom action will be called.

Now, go back to the ValidateSerialNumber InstallScript function, call UseDll() to load the DLL, then call the validate function in your DLL, then call UnUseDLL() to unload the DLL, and pass the result back to the installer. Maybe create a property and set the property based on the result of the validate function, then don't let the user go forward (when hitting Next), until the property is set to the correct value.

Something like that.
0 Kudos
gridman
Level 8

I've thought about this a lot because I had to do the same thing for my own project. This seemed like the best way to go.

Other people may have other ideas.
0 Kudos
klacounte
Level 6

Nicholasb, if you're using a Windows Installer based project you can just put the DLL in the Binary table then the Windows Installer will handle the extract & loading of your DLL.
0 Kudos
gridman
Level 8

I didn't know that klacounte. Thanks.
0 Kudos
Chikura
Level 3

Hi,

Previously i was having problems when i tried to load a DLL from the SUPPORTDIR directly. IS was unable to load the DLL.

We solved it by copying that DLL first to the system32 directory and then loading the dll from there.
Ur Customaction should do following:
1) Check for existence of DLL in system32.
2) If it exists delete that DLL.
3) Copy that DLL from SUPPORTDIR to system32.
4) Load DLL
5) Do whatever u want,,,,,,,
.
.
)Unload DLL
)Delete the DLL from system32.

Hope it helps,
Santhosh
0 Kudos
Nicolasb
Level 5

Thank you guy for these information! I'll try them today and give you news right here!
0 Kudos
klacounte
Level 6

Chikura wrote:
We solved it by copying that DLL first to the system32 directory and then loading the dll from there.

You can load a dll from any location as long as you specify the full path to the dll. Following this link for more info LoadLibrary Function. Copying the dll to the System32 directory works because that is in the dll search path but I would not recommend it. See this link for dll search order Dynamic-Link Library Search Order.

If your dll loads other dll's from that same directory then you'll need to call SetDllDirectory on XP SP1 or higher or SetCurrentDirectory on any other OS.
0 Kudos
Nicolasb
Level 5

I tried your suggestion and well, I think I missed something somewhere.. I'm sorry, but I got more questions.

I put my file in the supportdir and I loaded the DLL using UseDLL in an Installscript CA. The UseDll function worked fine, but I couldn't call my function... I think an exception occurs when I call the function. Do you have an example code on how to call a function in an external dll. The example along with the UseDll example isn't enough for me. Here is my function definition : extern "C" __declspec(dllexport) int __stdcall TestDll( int pOut )

Also, I explored the idea of putting my dll in the binary table. But here, I don't see where to put it in the project. I did not find the folder.

Thanks guys!
0 Kudos
esiemiat
Level 9

Did you prototype the DLL function before calling it. The prototype should look something like:

prototype MyDLL.MyFunction( INT, INT, INT ); 
0 Kudos
Nicolasb
Level 5

You mean that the prototype for function
extern "C" __declspec(dllexport) int __stdcall TestDll( int pOut )
in gaga.dll should be
prototype gaga.TestDll( INT, INT, INT ); 

(??) What is the argument pOut and what is the return value of the function ? And why the third int ? I would have declared my function that way :
prototype INT cdkc.TestDll( INT );
0 Kudos
esiemiat
Level 9

That was a sample from the help. The point was that you had to prototype your DLL function in InstallScript prior to calling it. Substitute you DLL name for MyDll, you function name for MyFunction, and list whatever your paramters are in the parameter list.
0 Kudos