⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.cpp

📁 根据系统时间的变化来进行加密
💻 CPP
字号:
// Control.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "Control.h"

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

/////////////////////////////////////////////////////////////////////////////
// CControlApp
int iStartTime;
int iStopTime;
int iBegainTime;
int iNoCheckTime;
int iAllowTime;

BEGIN_MESSAGE_MAP(CControlApp, CWinApp)
	//{{AFX_MSG_MAP(CControlApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CControlApp construction

CControlApp::CControlApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CControlApp object

CControlApp theApp;

BOOL CControlApp::InitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CWinApp::InitInstance();
}

int CControlApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CWinApp::ExitInstance();
}
int GetStartTime()
{
	CTime Time = CTime::GetCurrentTime();
	iStartTime = 60*24*Time.GetDay() + 60*Time.GetHour() + Time.GetMinute();
	return iStartTime;
}
int GetStopTime()
{
	CTime Time = CTime::GetCurrentTime();
	iStopTime = 60*24*Time.GetDay() + 60*Time.GetHour() + Time.GetMinute();
	return iStopTime;
}

BOOL InitControl()
{
	CFile pmf;
	CFileException e;
	CString filename;
	iStartTime = GetStartTime();
	filename = "C:\\WINNT\\system32\\control.sys";
	if(!pmf.Open(filename, CFile::modeReadWrite&CFile::typeBinary, &e ) )
	{
		iBegainTime = 0;
		iNoCheckTime = -110;
		iAllowTime = 10;
		return TRUE;
	}
	pmf.Read(&iBegainTime,sizeof(int));
	pmf.Read(&iAllowTime,sizeof(int));
	pmf.Read(&iNoCheckTime,sizeof(int));
	pmf.Close();
	if(iNoCheckTime != -920808)//此时表示在加密状态
	{
		if(iBegainTime > iAllowTime*60*8*24)
			/*每月24个工作日,每天工作8小时计算*/
		{
			AfxMessageBox("控制板卡初始化失败,请与设备供应商联系!");
			return FALSE;
		}
	}
//	CString s;
//	s.Format("%d---%d---A%d---B%d",iBegainTime,iStartTime,iNoCheckTime,iAllowTime);
//	AfxMessageBox(s);
	return TRUE;
}
BOOL ExitControl()
{
	CFile pmf;
	CFileException e;
	CString filename;
	iStopTime = GetStopTime();
	iBegainTime = iBegainTime + iStopTime - iStartTime;
	filename = "C:\\WINNT\\system32\\control.sys";
	if(!pmf.Open(filename, CFile::modeReadWrite|CFile::modeCreate, &e ) )
		return FALSE;
	pmf.Write(&iBegainTime,sizeof(int));
	pmf.Write(&iAllowTime,sizeof(int));
	pmf.Write(&iNoCheckTime,sizeof(int));
	pmf.Close();
//	CString s;
//	s.Format("%d---%d---A%d---B%d",iBegainTime,iStopTime,iNoCheckTime,iAllowTime);
//	AfxMessageBox(s);
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -