Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have previously developed all my source code under VC++ 6.0 under windows 2000.
I have upgraded my PC to XP and have now run into a problem using Following code:

Fun Part is this code works fine in win 2000 but not working in WIN XP:
WHat I am trying to do is when I click the exe file I will show me message that user have 30 days rmains for trial period and register that date (CURRENT DATE) IS FIRST CODE I wrote:
C++
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\\PARAMETERS",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE | KEY_READ,
NULL,
&hk,
&dwDisp);
 
// Check to see if the product code has been set in the registry entry.
int iRetValProdCode =
RegQueryValueEx(hk,
"USR:App Name\\ProductCode",
NULL,
NULL,
NULL,
NULL);
 
CAddaptApp* pAddaptApp = (CAddaptApp*)AfxGetApp();
 
if(iRetValProdCode != ERROR_SUCCESS)
{
   DWORD cbData = sizeof(pAddaptApp->m_dwProductCode);
 
   RegQueryValueEx(hk,
      "USR:App Name\\ProductCode",
      NULL,
      NULL,
      (LPBYTE)&pAddaptApp->m_dwProductCode,
      &cbData);
}
 
if(iRetValProdCode != ERROR_SUCCESS || pAddaptApp->m_dwProductCode == 0)
{ 
   // 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\\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,
            "USR:App Name\\FirstInstallDateTime",
            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\\FirstInstallDateTime",
      NULL,
      NULL,
      (LPBYTE)&timeStart,
      &cbData);
 
   timePassed = COleDateTime::GetCurrentTime() - timeStart;
   daysLeft = 30 - static_cast<int>(timePassed.GetTotalDays());
 
   CString strMessage;
 
   if (daysLeft <= 0)
   {
      CProductCodeDlg dlg;
      dlg.DoModal();
 
      if(pAddaptApp->m_dwProductCode != 0)
      {
         // Create the product code registry entry.
         RegSetValueEx(hk,
            "USR:App Name\\ProductCode",
            0,
            REG_DWORD,
            (LPBYTE) &pAddaptApp->m_dwProductCode,
            sizeof(pAddaptApp->m_dwProductCode));
      }
      else
      {
         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;
      }
   }
}


and Set of Code Register the product code:

C++
void CProductCodeDlg::OnDone() 
{
   UpdateData(TRUE);
   DWORD num = (m_dwProductCode & 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* pApp = (CAddaptApp*)AfxGetApp();
      pApp >SetAvailability();
 
      // Create the product code registry entry.
      HKEY hk;
      DWORD dwDisp;
      int iRetVal =RegCreateKeyEx(HKEY_LOCAL_MACHINE,
         "SOFTWARE\\AVTRON MANUFACTURING\\ADDAPT\\DON\\ADDAPT",
         0,
         NULL,
         REG_OPTION_NON_VOLATILE,
         KEY_WRITE | KEY_READ,
         NULL,
         &hk,
         &dwDisp);

      if(iRetVal == ERROR_SUCCESS)
      {
         RegSetValueEx(hk,
            "USR:App Name\\Section1ProductCode",
            0,
            REG_DWORD,
            (LPBYTE) &pApp->m_dwProductCode,
            sizeof(pApp ->m_dwProductCode));
      }
   }

CDialog::OnOK();

Thank you in advance and looking forward to hear from you soon.

Vijay Patel
Posted
Updated 10-Jan-12 5:10am
v3
Comments
Richard MacCutchan 10-Jan-12 11:17am    
The expression "not working" does not help anyone trying to figure out what may be the problem. Please give more detail of exactly what happens versus what you expect to happen.
Albert Holguin 10-Jan-12 13:23pm    
Not clear as to what the problem is... clarify.

1 solution

You are storing a COleDateTime in a DWORD registry entry (32 bit). COleDateTime uses internally the DATE data type which is a double (64 bit).
 
Share this answer
 
Comments
DrBones69 10-Jan-12 21:06pm    
Good catch! +5
Vijay Pate 11-Jan-12 10:24am    
I am actually working on 32 bit apps not 64 bit apps then what should I use.

Thank you very much.
Jochen Arndt 11-Jan-12 10:43am    
You may store the day number since 1970-01-01 calculated from time() or _time64(). To store the initial time, save static_cast<int>(_time64(NULL) / (24LL * 3600LL)). To get the elapsed number of days, subtract the integer value read from the registry from static_cast<int>(_time64(NULL) / (24LL * 3600LL)).
Vijay Pate 11-Jan-12 11:05am    
being novice I dont even have idea how to write this code could you please help where should I wrote your code.
Thank you very much.
Jochen Arndt 11-Jan-12 11:18am    
To store initial value when registry entry does not exist:
DWORD dwStart = static_cast<DWORD>(_time64(NULL) / (24LL * 3600LL));
DWORD cbData = sizeof(DWORD);
RegSetValueEx(hk, "USR:App Name\\FirstInstallDateTime", 0, REG_DWORD,
(LPBYTE)&dwStart, &cbData);
Get elapsed days:
RegQueryValueEx(hk, "USR:App Name\\FirstInstallDateTime", 0, REG_DWORD,
(LPBYTE)&dwStart, &cbData);
DWORD dwPassed = static_cast<DWORD>(_time64(NULL) / (24LL * 3600LL)) - dwStart;
int nDaysLeft = 30 - static_cast<int>dwPassed;

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