Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
After trial period finish (30days) software moved to ProductCode Page, where technical support department will provide License # for rest of the period this product code generated in KeyCode generated.
Is there anyway I can provide that code which will allow end user to utilize the code for rest of the life of software.

Thank you very mucch.

Vijay Patel
After 30 days trail period over the Productcode Page will pop up, which will ask end user to insert product code in the form. This Product code will be generated in KEYCODE GENERATOR.
My question : since the trial period is over there is no return for customer. How can I give full permission on new software to end user from KEYGENERATOR and remove Date from registry and give new date to new software from code mentioned below:
C++
// keyCodeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "keyCode.h"
#include "keyCodeDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKeyCodeDlg dialog
CKeyCodeDlg::CKeyCodeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CKeyCodeDlg::IDD, pParent), m_dwProductCode(0), m_dwKeyCode(0)

{
//{{AFX_DATA_INIT(CKeyCodeDlg)
m_Option1 = 1;
m_Option2 = m_Option3 = m_Option4 = m_Option5 = 0;
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CKeyCodeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKeyCodeDlg)
DDX_Text(pDX, IDC_PRODUCT_CODE, m_dwProductCode);
DDX_Text(pDX, IDC_KEY, m_dwKeyCode);
DDX_Check(pDX, IDC_RADIO1, m_Option1);
DDX_Check(pDX, IDC_RADIO2, m_Option2);
DDX_Check(pDX, IDC_RADIO3, m_Option3);
DDX_Check(pDX, IDC_RADIO4, m_Option4);
//DDX_Check(pDX, IDC_RADIO5, m_Option5);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CKeyCodeDlg, CDialog)
//{{AFX_MSG_MAP(CKeyCodeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_BN_CLICKED(IDCANCEL, OnCancel)
ON_EN_CHANGE(IDC_KEY, OnKeyCodeEntry)
ON_BN_CLICKED(IDC_CALC, OnCalc)
ON_BN_CLICKED(IDC_RADIO1, OnOption)
ON_BN_CLICKED(IDC_RADIO2, OnOption)
ON_BN_CLICKED(IDC_RADIO3, OnOption)
ON_BN_CLICKED(IDC_RADIO4, OnOption)
//ON_BN_CLICKED(IDC_RADIO5, OnOption)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKeyCodeDlg message handlers
BOOL CKeyCodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
GetDlgItem(IDC_RADIO5)->EnableWindow(FALSE);

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

GotoDlgCtrl(GetDlgItem(IDC_KEY));
UpdateData(FALSE);

return FALSE; // return TRUE unless you set the focus to a control
}

void CKeyCodeDlg::OnCalc()
{
int options = 32;

if(m_Option2)
options += 64;

if(m_Option3)
options += 128;

if(m_Option4)
options += 256;

if(m_Option5)
options += 512;

if(m_dwKeyCode>10)
{
m_dwProductCode = ( (m_dwKeyCode + 1001000) & 0x0ffc1f);
m_dwProductCode = m_dwProductCode + options;
}

UpdateData(FALSE);
}

void CKeyCodeDlg::OnOption()
{
if( m_Option2 || m_Option3 || m_Option4 /*|| m_Option5*/ )
{
m_Option1 = ((CButton*)GetDlgItem(IDC_RADIO1))->GetCheck();

if ( m_Option1 )
{ // reset for basic only
m_Option2 = m_Option3 = m_Option4 = m_Option5 = 0;
UpdateData(FALSE);
}
}

if( !(m_Option1 && m_Option2 && m_Option3 && m_Option4 && m_Option5) )
m_Option1 = 1; // something always available

m_Option2 = ((CButton*)GetDlgItem(IDC_RADIO2))->GetCheck();
if(m_Option2 == 1)
m_Option1 = 0;

m_Option3 = ((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck();
if(m_Option3 == 1)
m_Option1 = 0;

m_Option4 = ((CButton*)GetDlgItem(IDC_RADIO4))->GetCheck();
if(m_Option4 == 1)
m_Option1 = 0;

//m_Option5 = ((CButton*)GetDlgItem(IDC_RADIO5))->GetCheck();
//if(m_Option5 == 1)
// m_Option1 = 0;

UpdateData(FALSE);
}

void CKeyCodeDlg::OnOK()
{
return;
}

void CKeyCodeDlg::OnKeyCodeEntry()
{
UpdateData(TRUE);
}

void CKeyCodeDlg::OnCancel()
{
CDialog::EndDialog(IDCANCEL);
}

void CKeyCodeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CKeyCodeDlg::OnPaint() 
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

HBRUSH CKeyCodeDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
// Call the base class implementation first! Otherwise, it may
// undo what we're trying to accomplish here.
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// Are we painting the IDC_MYSTATIC control? We can use
// CWnd::GetDlgCtrlID() to perform the most efficient test.
if (pWnd->GetDlgCtrlID() == IDC_PRODUCT_CODE)
{
// Set the text color to red
pDC->SetTextColor(RGB(255, 0, 0));

// Set the background mode for text to transparent 
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);

// Return handle to our CBrush object
//hbr = m_brush;
}

return hbr;
}

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



Additional code for TimeSpan and registry entry is as follow:

 SetAvailability();

    
    COleDateTime timeStart;
    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\\Parameters",
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,
"FirstInstallDateTime",
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,
"FirstInstallDateTime",
0,
REG_DWORD,
(LPBYTE) &currDateTime,
sizeof(currDateTime));
}

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

DWORD cbData = sizeof(timeStart);
RegQueryValueEx(hk,
"FirstInstallDateTime",
NULL,
NULL,
(LPBYTE)&timeStart,
&cbData);

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

CString strMessage;

if (daysLeft <= 0)
{ 
("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);

CDialog dlg(IDD_PRODUCTCODE_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);

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

// User selected No, close the application.
if(iRespVal == IDNO)
return FALSE;
}</int>
Posted
Updated 10-Oct-11 8:30am
v8
Comments
Richard MacCutchan 3-Oct-11 13:14pm    
Most interesting, do you have a question?
Vijay Pate 3-Oct-11 13:21pm    
I need to add SystemDateTime or curentdatetime to Registry with this code.
Richard MacCutchan 3-Oct-11 14:37pm    
OK, and what problem are you having that prevents you from doing it?

Vijay Pate 3-Oct-11 15:49pm    
I dont have any experience and I am getting road block when assigning the value.
Thank you very much.
Chuck O'Toole 3-Oct-11 16:10pm    
I assume that phrase "when assigning the value" means something to you. It means nothing to us. We do not know what is in your mind. So, explain it as if the person you're talking to has no idea what you've tried or what error you've recieved or what conceptual road block you've hit. You have got to give us more precise information about your problem.

1 solution

Go to MSDN or Google the CTime class. The various constructors allow for interpreting time input in different forms. Then look at the GetAsSystemTime() member to convert to a SYSTEMTIME object. The GetCurrentTime() will get you 'now'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900