Window Registry with Time Stamp

I have buiild software with 30 days trial.

After 30 days enduser(or Client) will call to obtain key code and reactivate the software and code I have worked with is as follow:
SetAvailability();

COleDateTime timeStart;
// COleDateTime timeEnd(30.0);
COleDateTimeSpan timePassed;


int daysLeft = 0;

HKEY hk;
DWORD dwDisp;

// Open the Registry key, if it doesn't exist, it will be created.
RegCreateKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\AVTRON MANUFACTURING\\ADDAPT\\DON\\ADDAPT",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE | KEY_READ,
NULL,
&hk,
&dwDisp);

// Check to see if the install date has been set in the registry entry. If it doesn't exist, create
// the registry entry.

int iRetVal = RegQueryValueEx(hk,
"USR:App Name\\Section1",
NULL,
NULL,
NULL,
NULL);

COleDateTime currDateTime = COleDateTime::GetCurrentTime();

if(iRetVal != ERROR_SUCCESS)
{
// Registry entry doesn't exist, create it, and set to the current date.
RegSetValueEx(hk,
"USR:App Name\\Section1",
0,
REG_DWORD,
(LPBYTE) &currDateTime,
sizeof(currDateTime));
}

timeStart = COleDateTime::GetCurrentTime(); // Date and time of the installation.

DWORD cbData = sizeof(timeStart);
RegQueryValueEx(hk,
"USR:App Name\\Section1",
NULL,
NULL,
(LPBYTE)&timeStart,
&cbData);

timePassed = COleDateTime::GetCurrentTime() - timeStart;
daysLeft = 30 - static_cast(timePassed.GetTotalDays());

CString strMessage;

if (daysLeft <= 0)
{
strMessage.Format("ADDapt was not activated within 30 days of \n"
"installation, and will currently not function. \n"
"To activate, please call Avtron Field Service \n"
"at 216-642-1230 ext 1214.\n"
"The %d days trial period started on the day you installed ADDapt.\n"
"The application will now close.", daysLeft);

//AfxMessageBox(strMessage, MB_OK | MB_ICONSTOP);



CProductCodeDlg dlg;
dlg.DoModal();
// User selected No, close the application.
return FALSE;
}
else
{
strMessage.Format(_T("ADDapt is operating under a trial license. \n")
_T("You have %d" " days to activate ADDapt with a valid license.\n")
_T("To activate, Please call Avtron Field Service at 216 642-1230 ext 1214. \n")
_T("Do you want to Proceed?"), daysLeft);

int iRespVal = AfxMessageBox(strMessage, MB_YESNO | MB_ICONEXCLAMATION);

// User selected No, close the application.
if(iRespVal == IDNO)
return FALSE;
}



*****************************************************************************************



//ProductCode.CPP



// ProductCode.cpp : implementation file
//

#include "stdafx.h"
#include "Parameters.h"
#include "AddaptApp.h"

#include "ProductCode.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

const DWORD CONFUSER = 32767;
/////////////////////////////////////////////////////////////////////////////
// CProductCodeDlg dialog
CProductCodeDlg::CProductCodeDlg(CWnd* pParent) : CDialog(CProductCodeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChange)
m_strAddapt98 = _T("Activation Required");
m_strSA = _T("Purchase Required");
m_strViewer = _T("Purchase Required");
m_dwSerialNum = 0;
m_dwProductCode = 0;
//}}AFX_DATA_INIT
}

/////////////////////////////////////////////////////////////////////////////
// CProductCodeDlg dialog
void CProductCodeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProductCodeDlg)
DDX_Text(pDX, IDC_ADDAPT98, m_strAddapt98);
DDX_Text(pDX, IDC_RTD, m_strSA);
DDX_Text(pDX, IDC_VIEWER, m_strViewer);
DDX_Text(pDX, IDC_PRODUCTCODE, m_dwProductCode);
DDX_Text(pDX, IDC_SERIALNUM, m_dwSerialNum);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CProductCodeDlg, CDialog)
//{{AFX_MSG_MAP(CProductCodeDlg)
ON_EN_CHANGE(IDC_PRODUCTCODE, OnProductCodeEntry)
ON_BN_CLICKED(ID_DONE, OnDone)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProductCodeDlg message handlers
BOOL CProductCodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();

CAddaptApp* pAddaptApp = (CAddaptApp*)AfxGetApp();
m_dwSerialNum = pAddaptApp->m_dwSerialNum;
m_dwProductCode = pAddaptApp->m_dwProductCode;
m_dwInitialCode = m_dwProductCode;

BOOL bDisableEntry = FALSE;

if (pAddaptApp->m_bSA_Available)
m_strSA = "Available";

if (pAddaptApp->m_bViewer_Available)
m_strViewer = "Available";

if (pAddaptApp->m_bProductCodeFound)
{
m_strAddapt98 = "Available";

if( pAddaptApp->m_bViewer_Available )
bDisableEntry = TRUE; // all options are available - good customer
} // dont let anyone screw things up
else
{
if (m_dwProductCode == 0)
m_strAddapt98 = "Activation Required";
else
m_strAddapt98 = "Product Code Invalid";

m_strSA = "Purchase Required";
m_strViewer = "Purchase Required";


}

CWnd* pWnd = GetDlgItem(IDC_PRODUCTCODE);
if(bDisableEntry)
pWnd->EnableWindow(FALSE);
else
pWnd->EnableWindow(TRUE);

UpdateData(FALSE);
return TRUE;
}

void CProductCodeDlg::OnProductCodeEntry()
{
UpdateData(TRUE);
}

void CProductCodeDlg::OnOK()
{ // update controls
UpdateData(TRUE);

CAddaptApp* pApp = (CAddaptApp*)AfxGetApp();
DWORD num = (m_dwProductCode & 0x02e0);

if( (m_dwProductCode == 0x02e0 && pApp->m_bBeta) ||
m_dwProductCode != m_dwInitialCode &&
m_dwProductCode >= ( (m_dwSerialNum + 1001000) & 0xfff1f) &&
m_dwProductCode <= ( ((m_dwSerialNum + 1001000) & 0xfff1f) + 225) )
{

CParameters::ProductCode(num);
pApp->SetAvailability();

if (pApp->m_bProductCodeFound)
m_strAddapt98 = "Activation Required";

if (pApp->m_bSA_Available)
m_strSA = "Available";

if (pApp->m_bViewer_Available)
m_strViewer = "Available";


UpdateData(FALSE);
}
}

void CProductCodeDlg::OnDone()
{
UpdateData(TRUE);

//CAddaptApp* pApp = (CAddaptApp*)AfxGetApp();
DWORD num = (m_dwProductCode & 0x02e0);

/*if( m_dwProductCode != m_dwInitialCode &&
m_dwProductCode >= ( (m_dwSerialNum + 1001000) & 0xffc1f) &&
m_dwProductCode <= ( ((m_dwSerialNum + 1001000) & 0xffc1f) + 0x02e0))*/

if( (m_dwProductCode == 0x02e0 ) ||
m_dwProductCode != m_dwInitialCode &&
m_dwProductCode >= ( (m_dwSerialNum + 1001000) & 0xfff1f) &&
m_dwProductCode <= ( ((m_dwSerialNum + 1001000) & 0xfff1f) + 225) )
{
CParameters::ProductCode(num);
((CAddaptApp*)AfxGetApp())->SetAvailability();
}

CDialog::OnOK();
}

void CProductCodeDlg::OnCancel()
{
CDialog::OnCancel();
}


*************************************************************

What I am trying to do here once the product code insert in PROCUDTCODE FORM it will mentioned that it is AVAILABLE and MAIN MANU FORM will pop and application remains working.
Last edited on
Topic archived. No new replies allowed.