📄 msvcdemodlg.cpp
字号:
// MSVCDEMODlg.cpp : implementation file
//
#include "stdafx.h"
#include "MSVCDEMO.h"
#include "MSVCDEMODlg.h"
#include "RCGrandDogW32.h"
/////////////////////////////////////////////////////////////////////////////
// CMSVCDEMODlg dialog
CMSVCDEMODlg::CMSVCDEMODlg(CWnd* pParent /*=NULL*/)
: CDialog(CMSVCDEMODlg::IDD, pParent)
{
//initialize the member variable
m_ulCurrentDogHandle=0;
m_iDogIndex = 0;
m_ulOpenFlag=RC_OPEN_FIRST_IN_LOCAL;
m_ucPasswordType = RC_PASSWORDTYPE_USER;
m_ucKeyType = RC_KEY_SIGN;
m_bCallOpenFirstInLocal=false;
//{{AFX_DATA_INIT(CMSVCDEMODlg)
m_strProductName = _T("GrandDog");
m_strOpenFlag = _T("1: OpenFirstInLocal");
m_sDirID = 0;
m_sFileID = 0;
m_strPassword = _T("12345678");
m_strUpgradeFilePath = _T("");
m_iKeyIndex = 0;
m_iPasswordIndex = 0;
m_strResult = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
for(int iCount =0;iCount<32;iCount++)
{
m_ulDogHandleArray[iCount] = 0;
}
}
void CMSVCDEMODlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMSVCDEMODlg)
DDX_Text(pDX, IDC_EDIT_PRODUCT_NAME, m_strProductName);
DDV_MaxChars(pDX, m_strProductName, 15);
DDX_CBString(pDX, IDC_COMBO_OPEN_FLAG, m_strOpenFlag);
DDX_Text(pDX, IDC_EDIT_DIR_ID, m_sDirID);
DDX_Text(pDX, IDC_EDIT_FILE_ID, m_sFileID);
DDX_Text(pDX, IDC_EDIT_PASSWORD, m_strPassword);
DDX_Text(pDX, IDC_EDIT_UPGRADE_FILE_PATH, m_strUpgradeFilePath);
DDV_MaxChars(pDX, m_strUpgradeFilePath, 128);
DDX_Radio(pDX, IDC_RADIO_SIGN_KEY, m_iKeyIndex);
DDX_Radio(pDX, IDC_RADIO_USER, m_iPasswordIndex);
DDX_Text(pDX, IDC_STATIC_RESULT, m_strResult);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMSVCDEMODlg, CDialog)
//{{AFX_MSG_MAP(CMSVCDEMODlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_OPEN_DOG, OnButtonOpenDog)
ON_BN_CLICKED(IDC_BUTTON_GET_DOG_INFO, OnButtonGetDogInfo)
ON_BN_CLICKED(IDC_BUTTON_CLOSE_DOG, OnButtonCloseDog)
ON_BN_CLICKED(IDC_BUTTON_GET_PRODUCT_INFO, OnButtonGetProductInfo)
ON_BN_CLICKED(IDC_BUTTON_VERIFY_PASSWORD, OnButtonVerifyPassword)
ON_BN_CLICKED(IDC_BUTTON_CHANGE_PASSWORD, OnButtonChangePassword)
ON_BN_CLICKED(IDC_BUTTON_SET_KEY, OnButtonSetKey)
ON_BN_CLICKED(IDC_BUTTON_SIGN_DATA, OnButtonSignData)
ON_BN_CLICKED(IDC_BUTTON_ENCRYPT_DATA, OnButtonEncryptData)
ON_BN_CLICKED(IDC_BUTTON_CONVERT_DATA, OnButtonConvertData)
ON_BN_CLICKED(IDC_BUTTON_DECRYPT_DATA, OnButtonDecryptData)
ON_BN_CLICKED(IDC_BUTTON_GET_RANDOM, OnButtonGetRandom)
ON_BN_CLICKED(IDC_BUTTON_CREATE_DIR, OnButtonCreateDir)
ON_BN_CLICKED(IDC_BUTTON_DELETE_FILE, OnButtonDeleteFile)
ON_BN_CLICKED(IDC_BUTTON_CREATE_FILE, OnButtonCreateFile)
ON_BN_CLICKED(IDC_BUTTON_DELETE_DIR, OnButtonDeleteDir)
ON_BN_CLICKED(IDC_BUTTON_READ_FILE, OnButtonReadFile)
ON_BN_CLICKED(IDC_BUTTON_VISIT_LICENSE_FILE, OnButtonVisitLicenseFile)
ON_BN_CLICKED(IDC_BUTTON_WRITE_FILE, OnButtonWriteFile)
ON_BN_CLICKED(IDC_BUTTON_DEFLAG_FILE_SYSTEM, OnButtonDeflagFileSystem)
ON_BN_CLICKED(IDC_BUTTON_EXECUTE_FILE, OnButtonExecuteFile)
ON_BN_CLICKED(IDC_BUTTON_GET_REQUEST, OnButtonGetRequest)
ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
ON_BN_CLICKED(IDC_BUTTON_UPGRADE, OnButtonUpgrade)
ON_CBN_SELCHANGE(IDC_COMBO_OPEN_FLAG, OnSelchangeComboOpenFlag)
ON_BN_CLICKED(IDC_RADIO_USER, OnRadioUser)
ON_BN_CLICKED(IDC_RADIO_DEVELOPER, OnRadioDeveloper)
ON_BN_CLICKED(IDC_RADIO_SIGN_KEY, OnRadioSignKey)
ON_BN_CLICKED(IDC_RADIO_EN_DECRYPT_KEY, OnRadioEnDecryptKey)
ON_BN_CLICKED(IDC_BUTTON_CHECK_DOG, OnButtonCheckDog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMSVCDEMODlg message handlers
BOOL CMSVCDEMODlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CMSVCDEMODlg::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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMSVCDEMODlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMSVCDEMODlg::OnButtonOpenDog()
{
HRESULT hrReturnCode;
int iCount;
UpdateData(TRUE);
memset(m_cProductName, 0, 16);
memcpy(m_cProductName, m_strProductName, m_strProductName.GetLength());
if (m_ulCurrentDogHandle!=0)//You have opened dog before
{
if(RC_OPEN_FIRST_IN_LOCAL == m_ulOpenFlag)
{
m_ulCurrentDogHandle=0;
//first step, Close all opened Dog handle
for(iCount=0;iCount<m_iDogIndex;iCount++)
{
if(m_ulDogHandleArray[iCount]!=0)
{
rc_CloseDog(m_ulDogHandleArray[iCount]);
m_ulDogHandleArray[iCount] = 0;
}
}
m_iDogIndex=0;
m_bCallOpenFirstInLocal = false;
//second step, Open Dog Again.
hrReturnCode = rc_OpenDog(m_ulOpenFlag,m_cProductName,&m_ulCurrentDogHandle);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Open dog failed!\nThe error code is 0X%X.",hrReturnCode);
UpdateData(FALSE);
return;
}
else
{
m_strResult.Format("Open dog succeeded!\nThe dog handle is 0X%X.",m_ulCurrentDogHandle);
m_iDogIndex=0;
m_bCallOpenFirstInLocal = true;
UpdateData(FALSE);
return ;
}
}
else if(RC_OPEN_NEXT_IN_LOCAL == m_ulOpenFlag)
{
if(m_bCallOpenFirstInLocal == false)
{
m_strResult.Format("You should use OpenFirstInLocal to call OpenDog!");
UpdateData(FALSE);
return;
}
else
{
unsigned long ulTmpDogHandle;
ulTmpDogHandle = m_ulCurrentDogHandle;
hrReturnCode = rc_OpenDog(m_ulOpenFlag,m_cProductName,&ulTmpDogHandle);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Open dog failed!\nThe error code is 0X%X.",hrReturnCode);
UpdateData(FALSE);
return;
}
else
{
m_iDogIndex++;
m_ulDogHandleArray[m_iDogIndex]=ulTmpDogHandle;
m_ulCurrentDogHandle=ulTmpDogHandle;
m_strResult.Format("Open dog succeeded!\nThe dog handle is 0X%X.",m_ulCurrentDogHandle);
//m_iDogIndex=0;
m_bCallOpenFirstInLocal = true;
UpdateData(FALSE);
return ;
}
}
}
else if(RC_OPEN_IN_LAN == m_ulOpenFlag
|| RC_OPEN_LOCAL_FIRST == m_ulOpenFlag
|| RC_OPEN_LAN_FIRST == m_ulOpenFlag)
{
m_ulCurrentDogHandle=0;
//first step, Close all opened Dog handle
for(iCount=0;iCount<m_iDogIndex;iCount++)
{
if(m_ulDogHandleArray[iCount]!=0)
{
rc_CloseDog(m_ulDogHandleArray[iCount]);
m_ulDogHandleArray[iCount] = 0;
}
}
m_iDogIndex=0;
m_bCallOpenFirstInLocal = false;
//second step, Open Dog Again.
hrReturnCode = rc_OpenDog(m_ulOpenFlag,m_cProductName,&m_ulCurrentDogHandle);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Open dog failed!\nThe error code is 0X%X.",hrReturnCode);
UpdateData(FALSE);
return;
}
else
{
m_strResult.Format("Open dog succeeded!\nThe dog handle is 0X%X.",m_ulCurrentDogHandle);
UpdateData(FALSE);
return ;
}
}
else
{
;
}
}
else//m_ulCurrentDogHandle==0
{
if(RC_OPEN_NEXT_IN_LOCAL == m_ulOpenFlag)
{
m_strResult.Format("You should use OpenFirstInLocal to call OpenDog!");
}
else
{
hrReturnCode = rc_OpenDog(m_ulOpenFlag,m_cProductName,&m_ulCurrentDogHandle);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Open dog failed!\nThe error code is 0X%X.",hrReturnCode);
UpdateData(FALSE);
return;
}
else
{
m_strResult.Format("Open dog succeeded!\nThe dog handle is 0X%X.",m_ulCurrentDogHandle);
if(RC_OPEN_FIRST_IN_LOCAL == m_ulOpenFlag)
{
m_iDogIndex=0;
m_bCallOpenFirstInLocal = true;
m_ulDogHandleArray[0] = m_ulCurrentDogHandle;
}
UpdateData(FALSE);
return ;
}
}
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonCheckDog()
{
HRESULT hrReturnCode;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
//Call RC_CheckDog to judge whether the Hardware Dog exists or not
hrReturnCode = rc_CheckDog(m_ulCurrentDogHandle);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Check dog failed!\nThe error code is 0X%X.",hrReturnCode);
}
else
{
m_strResult.Format("Check dog succeeded!");
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonGetDogInfo()
{
HRESULT hrReturnCode;
RC_HARDWARE_INFO HardwareInfo;
ULONG ulLen= sizeof(HardwareInfo);
CString strTmp;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid Dog handle.\nYou should call OpenDog first!");
UpdateData(FALSE);
return;
}
//Call RC_GetDogInfo to get the Hardware Dog Infomation(SerialNumber, CurrentNumber, DogType, DogModel)
hrReturnCode = rc_GetDogInfo(m_ulCurrentDogHandle,&HardwareInfo,&ulLen);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Get dog information failed!\nThe error code is 0X%X.",hrReturnCode);
}
else
{
m_strResult.Format("GetDogInfo succeeded!\n");
strTmp.Format("The serial number is Dec:%u Hex:0X%X\nThe current number is Dec:%u Hex:0X%X\n"
,HardwareInfo.ulSerialNumber,HardwareInfo.ulSerialNumber,
HardwareInfo.ulCurrentNumber,HardwareInfo.ulCurrentNumber);
m_strResult = m_strResult + strTmp;
if (RC_DOGTYPE_LOCAL == HardwareInfo.ucDogType)
{
strTmp.Format("The dog type is STAND-ALONE dog. \n");
m_strResult = m_strResult + strTmp;
}
else if (RC_DOGTYPE_NET == HardwareInfo.ucDogType)
{
strTmp.Format("The dog type is NET dog. \n");
m_strResult = m_strResult + strTmp;
}
strTmp.Format("The dog model is %c%c%c%c",HardwareInfo.ucDogModel[0],HardwareInfo.ucDogModel[1],HardwareInfo.ucDogModel[2],HardwareInfo.ucDogModel[3]);
m_strResult = m_strResult + strTmp;
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonGetProductInfo()
{
HRESULT hrReturnCode;
ULONG ulProductCurrentNo;
CString strTmp;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
//Call RC_GetProductInfo to get the product information(Product name Product current number)
hrReturnCode = rc_GetProductCurrentNo(m_ulCurrentDogHandle,&ulProductCurrentNo);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Get product current number failed!\nThe error code is 0X%X.",hrReturnCode);
}
else
{
m_strResult.Format("Get product current number succeeded!\nThe poduct current number is:");
strTmp.Format("Dec:%u Hex:0X%X",ulProductCurrentNo,ulProductCurrentNo);
m_strResult = m_strResult + strTmp;
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonCloseDog()
{
HRESULT hrReturnCode;
int iCount;
UpdateData(TRUE);
//Close all opened dog
for(iCount=0;iCount<m_iDogIndex+1;iCount++)
{
if(m_ulDogHandleArray[iCount]!=0)
{
hrReturnCode = rc_CloseDog(m_ulDogHandleArray[iCount]);
if (S_OK != hrReturnCode)
{
m_strResult.Format("Close dog failed!\nThe error code is 0X%X",hrReturnCode);
UpdateData(FALSE);
return;
}
else
{
m_ulDogHandleArray[iCount] = 0;
}
}
}
if(RC_OPEN_IN_LAN == m_ulOpenFlag
|| RC_OPEN_LAN_FIRST == m_ulOpenFlag)
{
//Close the current Dog Handle;
if(m_ulCurrentDogHandle!=0)
{
hrReturnCode = rc_CloseDog(m_ulCurrentDogHandle);
if (S_OK != hrReturnCode)
{
m_strResult.Format("Close dog failed!\nThe error code is 0X%X",hrReturnCode);
UpdateData(FALSE);
return;
}
else
{
m_ulCurrentDogHandle= 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -