CFile file.Open assertion failure
-
This code is working for... Open and Read the file "login.rec" in "RECENT" folder and add "USER_NICK" info for a combobox and enumerate "USER_NICK" for same combobox from all existing "USER_NICK.use" file. this may have a assertion failure error please fix this code for good working and no error. BOOL CLogin::OnInitDialog() { CDialog::OnInitDialog(); CMainFrame *pMainWnd=(CMainFrame*)AfxGetMainWnd(); CDiet_caloView *pView=(CDiet_caloView*)pMainWnd->GetActiveView(); CString one1; CString one; CString RecentUser; one1.Format("%s\\RECENT",pView->m_strInstallPath); CFileStatus status; if( CFile::GetStatus( one1, status )) { } else { CreateDirectory(one1, NULL); } one.Format("%s\\RECENT\\login.rec",pView->m_strInstallPath); if( CFile::GetStatus( one, status )) { CFile file; file.Open(one,CFile::modeRead); char ch[300]; int FileLength=file.GetLength(); file.Read(ch, FileLength); char seps[]="#"; char *token; token=strtok(ch,seps); token=strtok(NULL,seps); RecentUser.Format("%s",token); file.Close(); } CString sPath2; sPath2.Format("%s",pView->m_strInstallPath); WIN32_FIND_DATA stFindData; HANDLE hFindFile; CString sFile,sTextFile; CString UserNick; BOOL nRet; int nCount; int num; char* sPtr=NULL; sTextFile = sPath2; sPath2 += "\\user\\*.use"; CString DD; hFindFile = FindFirstFile(sPath2,&stFindData); int doit=0; ((CComboBox *)GetDlgItem(IDC_COMBO1))->ResetContent(); while(hFindFile != INVALID_HANDLE_VALUE) { if(stFindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) { sFile = stFindData.cFileName; num=sFile.Find("."); UserNick.Format("%s",sFile.Left(num)); ((CComboBox*)GetDlgItem(IDC_COMBO1))->InsertString(doit,UserNick); nCount = ((CComboBox *)GetDlgItem(IDC_COMBO1))->GetCount(); if(UserNick==RecentUser) ((CComboBox *)GetDlgItem(IDC_COMBO1))->SetCurSel(doit); doit++; } nRet = FindNextFile(hFindFile,&stFindData); if( !nRet ) break; } FindClose(hFindFile); UpdateData(FALSE); return TRUE; //return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } Image will remind us some feelings and if I can ask someone about a problem, that's not a bad life.
-
This code is working for... Open and Read the file "login.rec" in "RECENT" folder and add "USER_NICK" info for a combobox and enumerate "USER_NICK" for same combobox from all existing "USER_NICK.use" file. this may have a assertion failure error please fix this code for good working and no error. BOOL CLogin::OnInitDialog() { CDialog::OnInitDialog(); CMainFrame *pMainWnd=(CMainFrame*)AfxGetMainWnd(); CDiet_caloView *pView=(CDiet_caloView*)pMainWnd->GetActiveView(); CString one1; CString one; CString RecentUser; one1.Format("%s\\RECENT",pView->m_strInstallPath); CFileStatus status; if( CFile::GetStatus( one1, status )) { } else { CreateDirectory(one1, NULL); } one.Format("%s\\RECENT\\login.rec",pView->m_strInstallPath); if( CFile::GetStatus( one, status )) { CFile file; file.Open(one,CFile::modeRead); char ch[300]; int FileLength=file.GetLength(); file.Read(ch, FileLength); char seps[]="#"; char *token; token=strtok(ch,seps); token=strtok(NULL,seps); RecentUser.Format("%s",token); file.Close(); } CString sPath2; sPath2.Format("%s",pView->m_strInstallPath); WIN32_FIND_DATA stFindData; HANDLE hFindFile; CString sFile,sTextFile; CString UserNick; BOOL nRet; int nCount; int num; char* sPtr=NULL; sTextFile = sPath2; sPath2 += "\\user\\*.use"; CString DD; hFindFile = FindFirstFile(sPath2,&stFindData); int doit=0; ((CComboBox *)GetDlgItem(IDC_COMBO1))->ResetContent(); while(hFindFile != INVALID_HANDLE_VALUE) { if(stFindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) { sFile = stFindData.cFileName; num=sFile.Find("."); UserNick.Format("%s",sFile.Left(num)); ((CComboBox*)GetDlgItem(IDC_COMBO1))->InsertString(doit,UserNick); nCount = ((CComboBox *)GetDlgItem(IDC_COMBO1))->GetCount(); if(UserNick==RecentUser) ((CComboBox *)GetDlgItem(IDC_COMBO1))->SetCurSel(doit); doit++; } nRet = FindNextFile(hFindFile,&stFindData); if( !nRet ) break; } FindClose(hFindFile); UpdateData(FALSE); return TRUE; //return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } Image will remind us some feelings and if I can ask someone about a problem, that's not a bad life.
You failed to mention what part of the code was in error? It's doubtful you will get much help, if at all, by posting a bunch of code, most of which is irrelevant, and asking folks to look at it and find the problem. You need to have gone through it and narrowed the problem down to just a few lines of code and ask for help with those. If you are going to use MFC, there is no need to use
char
,FindFirstFile()
,strtok()
, etc. That's not to say it won't work, but it makes no sense to bounce back and forth between the two unless you need something that MFC does/can not provide.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow