View Full Version : Trying to validate serial number using a VB DLL with one function or a custom action

08-25-2003, 07:14 PM

I am posting this message in hope someone can help me. First, my apology but I am new to Install Shield Express 4. I also apologize for the length of this message, but I didn’t want to leave anything out. Sorry for any inconvenience.

I thank you in advance for your help.

I have created an ActiveX DLL in Visual Basic 6 to validate serial numbers. My serial number is a 32 character field. I have set the following properties in Install Shield Express 4.:

Show Serial Number = YES
Serial Number Template = ????????-????-????-????-????????????
Each character is alphanumeric.
Serial Number Validation DLL = C:\Serial Number\SerialNumberValidation.dll

I created an ActiveX DLL project in Visual Basic with one function named ValidateSerialNumber that takes one string parameter. Here is part of my code. I have abbreviated some of the code and removed part of the ADO connection. I basically pass in a string of characters, look up that string in a database to make sure it exists, and if it does exists, then pass back a one for success. If unsuccessful, then pass back a zero. I also do some other things as well, but that isn’t important.

**Function declared in a class named clsSerialNumber in an Active X DLL project named SerialNumberValidation*****

Public Function ValidateSerialNumber(strInput As String) As Byte
Dim parRecordset As ADODB.Recordset
Dim parCommand As ADODB.Command
Dim param As ADODB.Parameter
On Error GoTo ValidateSerialNumber_Err
strInput = "{" & strInput & "}" ‘add leading and trailing {} to the input parameter because the field expects it.

Dim StrGUID As String
‘*********** removed ADO connection settings, connect to a SQL Server database.
Set parRecordset = New ADODB.Recordset
Set parCommand = New ADODB.Command

parCommand.CommandType = adCmdStoredProc
parCommand.CommandText = "VCVCIS_Lookup"
Set parCommand.ActiveConnection = parConnection
Set param = parCommand.CreateParameter("@ZID", adGUID, adParamInput, 16, strInput)
parCommand.Parameters.Append param
parRecordset.CursorLocation = adUseServer
parRecordset.Open parCommand, , adOpenStatic, adLockReadOnly, adCmdStoredProc
If parRecordset.EOF Then
'If parRecordset.RecordCount = 0 Then
MsgBox "Sorry the Key you entered is not found." & vbCrLf & vbCrLf & "Please try again.", vbExclamation, ErrDialogHeader
ValidateSerialNumber = 0
GoTo ValidateSerialNumber_Exit
'found the serial key and it matches, so pass back a ONE
ValidateSerialNumber = 1
End If 'parRecordset.RecordCount = 0
End If 'Err <> 0
On Error Resume Next
Set parRecordset = Nothing
Set parConnection = Nothing
If Err <> 0 Then Err.Clear
Exit Function
If Err = -2147217887 Then
'can't open the recordset because GUID is invalid
MsgBox "Sorry the Key you entered is not found." & vbCrLf & vbCrLf & "Please try again.", vbExclamation, ErrDialogHeader

MsgBox Error$
End If
ValidateSerialNumber = 0
Resume ValidateSerialNumber_Exit

End Function
**** end of abbreviated code

In Visual Basic 6, I have for test purposes added a standard exe project to a project group to test the ActiveX dll. And it works great. I then made the Activex into a DLL (File | Make SerailNumberValidation.dll) named SerialNumberValidation.dll (which has that one function). It is this file that I have set the Serial Number Validation DLL property to. And because the name of the function in my example is named ValidateSerialNumber, I put that in the Validate Function property.

When I run my setup, I get the error message,: Can not find the entry point of function ‘ValidateSerialNumber’, make sure it is exported.”

As a side note, I checked the dll file by Regsvr32 and it was successfully registered. I also checked the file properties.

I am guessing, but could be wrong, that Install Shield Express expects a function that does serial number validation with the following input parameters: (this came from the knowledge base – Simple Serial Number Validation DLL written in C++ )

HWnd =Handle of the main window handle of the installation
SSRCDIR = Source Directory of installation
SSuportDIR = Source Directory of Installation
SSerialNumber = Serial # supplied by end-user
SReserved = NULL and is reserved for future use.

Return type of the function is or should be CHAR APIEntry. I am not sure what that means since the function should return a 1 for success and 0 for not success.

From this you can see that my validation function only has one parameter and returns a byte for 1 or 0 in Visual Basic 6.

Does any one know what I am doing wrong and how to fix this?

I also wasn’t sure what the error message meant by “make sure it is exported”.

Lastly, I noticed the last section of my serial number was getting cut off. I am guessing my 32 character serial number is too long. Is this correct?

Thanks in advance.

As a workaround, I have also created a standard Visual Basic Executable that runs in place of the DLL I am using as a custom action. (I took out the serial number and added a custom action to call a exe.) That works great but I wasn’t sure how to capture a return exit code. If the user enters my serial number correctly, everything works great. If the user enters an incorrect serial number, I popup a message box stating the number is incorrect and to try again. However, if the user does not have a serial number and wishes to cancel the setup this is where my problem arises. If I add a cancel button to my standard exe application, the program will just close but the setup will remain open and I would like to cancel the setup once that is done. I wasn’t sure how to do that.

To sum up, the user decides to cancel the setup, so he or she clicks a cancel button on my customized serial number program (a program with one form for the user to enter in a serial number followed by an ok button to continue; or a cancel button to cancel) which is being run as a custom action just after the licensing agreement.

Here are the custom action properties I have set up in this work around:

Name = SerialNumberAction
File Name = C:\Serial Number\Serial Number.exe (This is the path to the compiled exe Serial Number Validation VB program)
Invoke = After Install Welcome Dialog
Wait for Action = YES
Run Once = YES
Execute = During Installation
Ignore Exit Code = NO. I am not sure how to capture this exit code since the program is a standalone application that validates a serial number and then closes. (I also had a message box popup stating the validation was okay as a test to make sure it was working properly.)
Conditions = No conditions

When I run the setup (by removing the serial number on the Customer Information dialog) and include this exe custom action, it works great except when the user cancels the custom action which then just continues with the setup which isn’t what I need. I would like to cancel the setup if the user clicks the cancel button on my serial number program.

Can any one help?

Thanks again in advance.