MFC,AFXMessage,ColeDateTime [英] MFC, AFXMessage, ColeDateTime
问题描述
我以前在Windows 2000下的VC ++ 6.0下开发了所有源代码.
我已将PC升级到XP,现在使用以下代码遇到问题:
有趣的是,此代码在win 2000中可以正常工作,但在WIN XP中不能正常工作:
我要尝试执行的操作是,当我单击exe文件时,我会显示以下消息:用户具有30天的试用期,并注册该日期(当前日期)为我编写的第一个代码:
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:
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:
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();
在此先感谢您,希望很快能收到您的来信.
Vijay Patel
Thank you in advance and looking forward to hear from you soon.
Vijay Patel
推荐答案
您正在将COleDateTime
存储在DWORD
注册表项(32位)中.COleDateTime
在内部使用DATE
数据类型,它是double
(64位).
You are storing aCOleDateTime
in aDWORD
registry entry (32 bit).COleDateTime
uses internally theDATE
data type which is adouble
(64 bit).
这篇关于MFC,AFXMessage,ColeDateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!