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

📄 msvcdemodlg.cpp

📁 彩虹狗的例子 值得一提的是
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	{
		m_strResult.Format("Create directory succeeded!\nThe directory ID is DEC:%d  HEX:0X%04X\nThe directory size is DEC:%d  HEX:0X%04X",m_sDirID,m_sDirID,usDirSize,usDirSize);
	}
	else
	{
		m_strResult.Format("Create directory failed!\nThe error code is 0X%X",hrReturnCode);
	}
	UpdateData(FALSE);
	
}


void CMSVCDEMODlg::OnButtonCreateFile() 
{
	HRESULT		hrReturnCode;
	USHORT		usFileSize = 110;	

	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_CreateFile to create file
	//We only create data file in here. You can create license file or algorithm file with Developer Tool.	
	hrReturnCode = rc_CreateFile(m_ulCurrentDogHandle,m_sDirID,m_sFileID,RC_TYPEFILE_DATA,usFileSize);
	if (S_OK == hrReturnCode)
	{
		m_strResult.Format("Create file succeeded!\nThe directory ID is DEC:%d  HEX:0X%04X \nThe File ID is DEC:%d  HEX:0X%04X\nThe file size is DEC:%d  HEX:0X%04X",
			m_sDirID,m_sDirID,m_sFileID,m_sFileID,usFileSize,usFileSize);
	}
	else
	{
		m_strResult.Format("Create file failed!\nThe error code is 0X%X",hrReturnCode);
	}
	UpdateData(FALSE);
}


void CMSVCDEMODlg::OnButtonWriteFile() 
{
	CString		strTmp;
	HRESULT		hrReturnCode;
	int			iCount;
	ULONG		ulPos=0;
	ULONG		ulLen=100;
	UCHAR		ucData[100];
	UpdateData(TRUE);

	if (m_ulCurrentDogHandle == 0)
	{
		m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
		UpdateData(FALSE);
		return;
	}
	for(iCount=0;iCount<100;iCount++)
	{
		ucData[iCount]=iCount;
	}
	//Call RC_WriteFile to write data to the specified file
	hrReturnCode = rc_WriteFile(m_ulCurrentDogHandle,m_sDirID,m_sFileID,ulPos,ulLen,ucData);
	if (hrReturnCode!=S_OK)
	{
		m_strResult.Format("Write file failed!\nThe error code is 0X%X.",hrReturnCode);
	}
	else
	{

		m_strResult.Format("Write file succeeded!\n\nThe write data is\n");
		for(iCount=0;iCount<(int)ulLen;iCount++)
		{
			strTmp.Format("0X%02X " ,ucData[iCount]);
			m_strResult = m_strResult+strTmp;
			if((iCount+1)%8==0)
			{
				strTmp.Format("\n");
				m_strResult = m_strResult+strTmp;
			}
		}
	}
	UpdateData(FALSE);
}


void CMSVCDEMODlg::OnButtonReadFile() 
{
	CString		strTmp;
	HRESULT		hrReturnCode;
	int			iCount;
	ULONG		ulPos=0;
	ULONG		ulLen=100;
	UCHAR		ucData[100];
	UpdateData(TRUE);

	if (m_ulCurrentDogHandle == 0)
	{
		m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
		UpdateData(FALSE);
		return;
	}
	memset(ucData,0,100);
	//Call RC_ReadFile to read data from the specified file.
	hrReturnCode = rc_ReadFile(m_ulCurrentDogHandle,m_sDirID,m_sFileID,ulPos,ulLen,ucData);
	if (hrReturnCode!=S_OK)
	{
		m_strResult.Format("Read file failed!\nThe error code is 0X%X.",hrReturnCode);
	}
	else
	{

		m_strResult.Format("Read file succeeded!\nThe read data is\n");
		for(iCount=0;iCount<(int)ulLen;iCount++)
		{
			strTmp.Format("0X%02X " ,ucData[iCount]);
			m_strResult = m_strResult+strTmp;
			if((iCount+1)%8==0)
			{
				strTmp.Format("\n");
				m_strResult = m_strResult+strTmp;
			}
		}
	}
	UpdateData(FALSE);
	
}

void CMSVCDEMODlg::OnButtonVisitLicenseFile() 
{
	HRESULT		hrReturnCode;
	BOOL		bShowNotify=TRUE;

	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_VisitLicenseFile to visit license file
	hrReturnCode = rc_VisitLicenseFile(m_ulCurrentDogHandle,m_sDirID,m_sFileID,bShowNotify);
	if (S_OK == hrReturnCode)
	{
		m_strResult.Format("Visit license file succeeded!\n");
	}
	else
	{
		m_strResult.Format("Visit license file failed!\nThe error code is 0X%X",hrReturnCode);
	}
	UpdateData(FALSE);
}

void CMSVCDEMODlg::OnButtonDeleteDir() 
{
	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_DeleteDir to delete the specified directory file.
	hrReturnCode = rc_DeleteDir(m_ulCurrentDogHandle,m_sDirID);
	if (S_OK == hrReturnCode)
	{
		m_strResult.Format("Delete directory succeeded!\n");
	}
	else
	{
		m_strResult.Format("Delete directory failed!\nThe error code is 0X%X",hrReturnCode);
	}
	UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonDeleteFile() 
{
	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_Deletefile to delete the specified file.
	hrReturnCode = rc_DeleteFile(m_ulCurrentDogHandle,m_sDirID,m_sFileID);
	if (S_OK == hrReturnCode)
	{
		m_strResult.Format("Delete file succeeded!\n");
	}
	else
	{
		m_strResult.Format("Delete file failed!\nThe error code is 0X%X",hrReturnCode);
	}
	UpdateData(FALSE);
}

void CMSVCDEMODlg::OnButtonDeflagFileSystem() 
{
	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_DefragFileSystem to defrag the file system of the specified directory in Hardware Dog.
	//If you want to defrag the root directory, usDirID should be 0x3F00.
	hrReturnCode = rc_DefragFileSystem(m_ulCurrentDogHandle,m_sDirID);
	if (S_OK == hrReturnCode)
	{
		m_strResult.Format("Defrag file system succeeded!\n");
	}
	else
	{
		m_strResult.Format("Defrag file system failed!\nThe error code is 0X%X",hrReturnCode);
	}
	UpdateData(FALSE);
}

void CMSVCDEMODlg::OnButtonExecuteFile() 
{
	UCHAR		ucDataIn[32];
	ULONG		ulInLen=32;
	UCHAR		ucDataOut[32];
	ULONG		ulOutLen=32;
	HRESULT		hrReturnCode;
	int			iCount;
	CString		strTmp;
	int			i;

	UpdateData(TRUE);
	if (m_ulCurrentDogHandle == 0)
	{
		m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
		UpdateData(FALSE);
		return;
	}
	for(i=0;i<32;i++)
	{
		ucDataIn[i] = i;
	}
	//Call RC_ExecuteFile to execute algorithm file and get the result.
	hrReturnCode = rc_ExecuteFile(m_ulCurrentDogHandle,m_sDirID,m_sFileID,ucDataIn,ulInLen,ucDataOut,&ulOutLen);
	if (S_OK == hrReturnCode)
	{
		m_strResult.Format("Execute file succeeded!\nThe input data is\n");
		for(iCount=0;iCount<(int)ulInLen;iCount++)
		{
			strTmp.Format("0X%02X " ,ucDataIn[iCount]);
			m_strResult = m_strResult+strTmp;
			if((iCount+1)%8==0)
			{
				strTmp.Format("\n");
				m_strResult = m_strResult+strTmp;
			}
		}
		strTmp.Format("\nThe output data is\n");
		m_strResult = m_strResult+strTmp;
		for(iCount=0;iCount<(int)ulOutLen;iCount++)
		{
			strTmp.Format("0X%02X " ,ucDataOut[iCount]);
			m_strResult = m_strResult+strTmp;
			if((iCount+1)%8==0)
			{
				strTmp.Format("\n");
				m_strResult = m_strResult+strTmp;
			}
		}

	}
	else
	{
		m_strResult.Format("Execute file failed!\nThe error code is 0X%X",hrReturnCode);
	}
	UpdateData(FALSE);
}

void CMSVCDEMODlg::OnButtonGetRequest() 
{
	HRESULT	hrReturnCode;
	UCHAR	ucRequestString[64];
	ULONG	ulLen=64;
	CString strTmp;
	int		iCount;

	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_GetUpgradeRequestString to get the upgrade request string.
	hrReturnCode = rc_GetUpgradeRequestString(m_ulCurrentDogHandle,ucRequestString,&ulLen);

	if (hrReturnCode!=S_OK)
	{
		m_strResult.Format("Get upgrade request string failed!\nThe error code is 0X%X.",hrReturnCode);
	}
	else
	{
		m_strResult.Format("Get upgrade request string succeeded!\n\nThe request string is:\n");
		for (iCount=0;iCount<64;iCount++)
		{
			strTmp.Format("%c",ucRequestString[iCount]);
			m_strResult = m_strResult+strTmp;
			if((iCount+1)%32==0)
			{
				strTmp.Format("\n");
				m_strResult = m_strResult+strTmp;
			}
		}

	}
	UpdateData(FALSE);
	
}

void CMSVCDEMODlg::OnButtonBrowse() 
{
	CFileDialog filedlg (TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Upgrade Files (*.upg) | *.upg||");
	if (filedlg.DoModal() == IDOK)
	{		
		m_strUpgradeFilePath = filedlg.GetPathName();
		UpdateData(false);
	}

}

void CMSVCDEMODlg::OnButtonUpgrade() 
{
	CString		strTmp;
	HANDLE		hHandle	;
	DWORD		dwLength;
	UCHAR *		pucTemp;
	BOOL		bRet;
	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;
	}
	hHandle = CreateFile(m_strUpgradeFilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
		                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if(INVALID_HANDLE_VALUE==hHandle)
	{
		m_strResult.Format("Open upgrade file failed!");
		UpdateData(FALSE);
		return;
	}


	dwLength = GetFileSize(hHandle,NULL);
	pucTemp = new unsigned char[dwLength+1];

	bRet = ReadFile(hHandle, pucTemp, dwLength, &dwLength, NULL);
	if(!bRet)
	{
		m_strResult.Format("Read upgrade file failed!");
		CloseHandle(hHandle);
		delete pucTemp;
		UpdateData(FALSE);
		return ;
	}
	CloseHandle(hHandle);
	hrReturnCode = rc_Upgrade(  m_ulCurrentDogHandle, pucTemp, dwLength);
	
	if(S_OK == hrReturnCode)
	{
		m_strResult.Format("Upgrade succeeded!");
	}
	else
	{
		m_strResult.Format("Upgrade failed!\nError code is :0x%x",hrReturnCode);
	}
	
	delete pucTemp;
	UpdateData(FALSE);
}

void CMSVCDEMODlg::OnSelchangeComboOpenFlag() 
{
	// TODO: Add your control notification handler code here
	CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_OPEN_FLAG);
	int iIndex = pCBox->GetCurSel();
	if (iIndex == CB_ERR)
	{
		return;
	}
	m_ulOpenFlag=iIndex+1;
	pCBox->GetLBText(iIndex, m_strOpenFlag);
	UpdateData(FALSE);
}

void CMSVCDEMODlg::OnRadioUser() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_ucPasswordType = RC_PASSWORDTYPE_USER;
	UpdateData(FALSE);

}

void CMSVCDEMODlg::OnRadioDeveloper() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_ucPasswordType = RC_PASSWORDTYPE_DEVELOPER;
	UpdateData(FALSE);
	
}

void CMSVCDEMODlg::OnRadioSignKey() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_ucKeyType = RC_KEY_SIGN;
	UpdateData(FALSE);
	
}

void CMSVCDEMODlg::OnRadioEnDecryptKey() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_ucKeyType = RC_KEY_AES;
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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