void CPersistentSymbolToolDlg::OnButtonDecode() 
{
	CFileDialog dlgFileOpen(TRUE, NULL, NULL, OFN_HIDEREADONLY, NULL);
	if(dlgFileOpen.DoModal() == IDOK)
	{
		CFileDialog dlgFileSave(FALSE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, NULL);
		if(dlgFileSave.DoModal() == IDOK)
		{
			try
			{
				FILE *fp = fopen(dlgFileOpen.GetPathName().GetBuffer(0), "rb");
				int len = 0;
				fread(&len, 4, 1, fp);
				unsigned char *bufSrc = new unsigned char[len];
				fread(bufSrc, len, 1, fp);
				fclose(fp);
				char *bufDst = new char[len + 1024];
				memset(bufDst, 0, len+1024);

				DecodePersistentSymbols((unsigned char*)bufDst, 0, bufSrc, len);
				
				fp = fopen(dlgFileSave.GetPathName().GetBuffer(0), "w");
				fwrite(bufDst, len, 1, fp);
				fclose(fp);
				delete[] bufSrc;
				delete[] bufDst;
			}
			catch(...)
			{
				m_strStatus = "Somthing is wrong.";
				UpdateData(FALSE);
			}
		}
	}
}
Exemple #2
0
CString CSettingDlg::GetOpenSoundFile()
{
	CFileDialog dlgFileOpen(FALSE,_T(".wav"),NULL,OFN_FILEMUSTEXIST,
		_T("Wav Files(*.wav)|*.wav||"),NULL);
	
	char Path[MAX_PATH];
	GetModuleFileName(NULL, Path,MAX_PATH);
	PathRemoveFileSpec(Path);
	strcat(Path,"\\sound");
	
	int StructSize = 0;
	DWORD dwVersion = GetVersion();
    if(dwVersion < 0x80000000)			//winnt/xp
		StructSize = 88;				//show new dialog
	else								//win9x
		StructSize = 76;				//show old dialog
	
	dlgFileOpen.m_ofn.lStructSize		= StructSize;
	dlgFileOpen.m_ofn.lpstrInitialDir	= _T(Path);
	if(dlgFileOpen.DoModal() == IDOK)
	{
		return (CString)dlgFileOpen.m_ofn.lpstrFile;
	}
	
	return _T("");
}
Exemple #3
0
void CChildView::OnCommandSendFile() 
{
	// Select the file
	CFileDialog dlgFileOpen(TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,_T("All files (*.*)|*.*||"),this);
	if (dlgFileOpen.DoModal() != IDOK)
		return;

	// Open the file
	HANDLE hFile = ::CreateFile(dlgFileOpen.GetPathName(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		// Obtain file length
		DWORD dwDataLen = ::GetFileSize(hFile,0);

		// Map the file into memory
		HANDLE hMap = ::CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,NULL);
		if (hMap != NULL)
		{
			LPVOID lpData = ::MapViewOfFile(hMap,FILE_MAP_READ,0,0,0);
			if (lpData)
			{
				// Write all data
				DWORD dwWritten = 0;
				m_serial.Write(lpData,dwDataLen,&dwWritten);

				// Display event
				CString strEvent;
				strEvent.Format(_T("Written %d bytes."), dwWritten);
				DisplayEvent(strEvent);

				// Unmap the view
				::UnmapViewOfFile(lpData);
			}

			// Close mapping
			::CloseHandle(hMap);
		}

		// Close file
		::CloseHandle(hFile);
	}
}