searching for text in a mixed file (text and hex)
I have the following code below to take a selected file and read it's
contents.
The app has a ListBox (IDC_FILELIST) and Static text (IDC_FILESELECTED).
More will be added later to process the read file.
How do I search for a text string when the file does contain 0x00's in it.
It is a mixed file containing text and hex data?
I compile with no errors and the filename does appear at IDC_FILESELECTED.
Please feel free to direct me in other things I am doing improperly.
BOOL CMyAppDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CListBox* List = (CListBox*)GetDlgItem(IDC_FILELIST);
List->ResetContent();
HANDLE hand;
WIN32_FIND_DATA tell;
CString William = "C:\\temp\\*.ppf"; //file I am listing have a .ppf
extension
LPCTSTR Ppath = William;
CString insert;
hand=FindFirstFile (Ppath, &tell);
if (hand != INVALID_HANDLE_VALUE){
insert = tell.cFileName;
List->AddString(insert);
}
Search:
if (FindNextFile(hand, &tell)){
insert = tell.cFileName;
List->AddString(insert);
goto Search;
}
UpdateData(false);
return TRUE;
}
void CMyAppDlg::OnSelchangeFilelist()
{
char cSelect[500];
int nSelect;
long lth;
FILE *in;
nSelect=SendDlgItemMessage(IDC_FILELIST, LB_GETCURSEL, 0, 0L);
DlgDirSelect((LPSTR) cSelect, IDC_FILELIST);
GetDlgItem(IDC_FILESELECTED)->SetWindowText(cSelect);
UpdateWindow();
Fname = "C:\\temp\\"; //set directory path
Fname += cSelect; //append filename selected
in = fopen (Fname, "rb"); //open the selected file for binary
reading
fseek(in, 0, SEEK_END); //Move File Pointer to EOF
lth = ftell(in); //Get position of FP
fseek(in, 0, SEEK_SET); //Move FP back to beginning of file
edi = new TCHAR[lth]; //create place for data (declared
"LPTSTR edi;" in header file
fread (edi, lth, 1, in); //read entire file into edi
fclose (in);
fileSize = (int)lth; //save the filelength for future use
}