PDA

View Full Version : ValidateSN Error



Robert11
01-06-2006, 11:36 AM
Below is the code for ValidateSN.dll. I added two functions to the sample that comes with ISEXP.

// ValidateSN.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include <tchar.h>
#include <stdlib.h>
#include "ValidateSN.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

LONG WINAPI ValidateSN(HWND hwnd, LPSTR szSrcDir, LPSTR szSupport, LPSTR szSerialNum, LPSTR szDbase)
{
//Copy serial number to temp variable before parsing
TCHAR szTemp[255];
_tcscpy(szTemp, szSerialNum);


//Get individual fields of the serial number (tokens separated by '-' chracter)
LPSTR szField1 = _tcstok( szTemp, TOKEN_SEPERATOR );
LPSTR szField2 = _tcstok( NULL, TOKEN_SEPERATOR );
LPSTR szField3 = _tcstok( NULL, TOKEN_SEPERATOR );
LPSTR szField4 = _tcstok( NULL, TOKEN_SEPERATOR );
LPSTR szField5 = _tcstok( NULL, TOKEN_SEPERATOR );

//#ifdef _DEBUG //Display Debug information
// CHAR szTmp[1024];
// wsprintf(szTmp, "szSerialNum=%s. \nField #1=%s \nField #2=%s \nField #3=%s", szSerialNum, szField1, szField2, szField3);
// MessageBox(GetFocus(), szTmp, "Serial Number Debug Window", MB_OK|MB_SYSTEMMODAL);
// #endif

//Validate three fields in this example
if (ValidateField1(szField1) != VALIDATION_SUCCESS)
{
// #ifdef _DEBUG //Display Debug information
// MessageBox(GetFocus(), szField1, "Field #1 Validation Failed", MB_OK|MB_SYSTEMMODAL);
// #endif

return VALDIATION_FAILED;
}
else if (ValidateField2(szField2) != VALIDATION_SUCCESS)
{
// #ifdef _DEBUG //Display Debug information
// MessageBox(GetFocus(), szField2, "Field #2 Validation Failed", MB_OK|MB_SYSTEMMODAL);
// #endif

return VALDIATION_FAILED;
}
else if (ValidateField3(szField3) != VALIDATION_SUCCESS)
{
// #ifdef _DEBUG //Display Debug information
// MessageBox(GetFocus(), szField3, "Field #3 Validation Failed", MB_OK|MB_SYSTEMMODAL);
// #endif

return VALDIATION_FAILED;
}
else if (ValidateField4(szField4) != VALIDATION_SUCCESS)
{
// #ifdef _DEBUG //Display Debug information
// MessageBox(GetFocus(), szField4, "Field #4 Validation Failed", MB_OK|MB_SYSTEMMODAL);
// #endif

return VALDIATION_FAILED;
}
else if (ValidateField5(szField5) != VALIDATION_SUCCESS)
{
// #ifdef _DEBUG //Display Debug information
// MessageBox(GetFocus(), szField5, "Field #5 Validation Failed", MB_OK|MB_SYSTEMMODAL);
// #endif

return VALDIATION_FAILED;
}
else
return VALIDATION_SUCCESS;
}

LONG ValidateField1(LPSTR szField1)
{
//First field must be the string 'Field1'
if (0 == _tcsicmp(szField1, SERIALNUM_FIELD1))
return VALIDATION_SUCCESS;
else
return VALDIATION_FAILED;
}

LONG ValidateField2(LPSTR szField2)
{

long lNumToValidate = atoi (szField2);

//Second field must be a multiple of 5
if ((lNumToValidate % 5) == 0)
return VALIDATION_SUCCESS;
else
return VALDIATION_FAILED;
}

LONG ValidateField3(LPSTR szField3)
{
//Don't do anything - accept all values in third field
return VALIDATION_SUCCESS;

}

LONG ValidateField4(LPSTR szField4)
{

long lNumToValidate = atoi (szField4);

//Fourth field must be a multiple of 3
if ((lNumToValidate % 3) == 0)
return VALIDATION_SUCCESS;
else
return VALDIATION_FAILED;
}

LONG ValidateField5(LPSTR szField5)
{

long lNumToValidate = atoi (szField5);

//Fifth field must be a multiple of 2
if ((lNumToValidate % 2) == 0)
return VALIDATION_SUCCESS;
else
return VALDIATION_FAILED;
}

I comiled the dll with VS 6.0 Enterprise Edition.

After I rebuild my ISX Setup, and test it out, I receive the following error message at the Serial No Screen.

Cannot Find the Entry Point of Function "ValidateSN" make sure it is exported.

Can some one point out my error please!

Thanks
bob

jvinton
01-06-2006, 04:11 PM
You need to export the functions so they can be called by the installer.

Add a .def file to your VC project. It will look something like this (although this viewer may alter the formatting)

LIBRARY MyDLLName
EXPORTS
MyFunctionName1
MyFunctionName2


Hope that helps.

Robert11
01-06-2006, 05:38 PM
That helped out on the Error message, but now I get nothing, even if it is the right Serial No.

Thanks
bob :confused:

jvinton
01-06-2006, 07:45 PM
Just guessing but check the values your function is returning and how you have set the Success Return Value in IS. Success must be non-zero but you need to tell IS what is acceptable.

Jay

Robert11
01-06-2006, 08:08 PM
Just guessing but check the values your function is returning and how you have set the Success Return Value in IS. Success must be non-zero but you need to tell IS what is acceptable.

Jay

My function is set to 2.

I have managed to make the DLL work, but the only trouble is I still get the message box showing the Serial No even if it is correct. I select the OK button on the Message Box, and the installation continues.

Any C++ programmers outthere that could help to refine this?
I just want to show an error message, ONLY IF the Serial No is wrong.

Thanks in advance
bob