Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CFile file.Open assertion failure

CFile file.Open assertion failure

Scheduled Pinned Locked Moved C / C++ / MFC
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arbrsoft
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • A arbrsoft

      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.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups