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. File search problem

File search problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
3 Posts 3 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.
  • R Offline
    R Offline
    RaajaOfSelf
    wrote on last edited by
    #1

    I have some problem in my code .Due to my inexpereicne iam not able to solve it . HANDLE hFile; LPWIN32_FIND_DATA FileData; hFile=FindFirstFile(str,FileData); if(hFile==INVALID_HANDLE_VALUE) { FindClose(hFile); return FALSE; } else { FindClose(hFile); AfxMessageBox("File Does Exists "); return TRUE; } This is a MFC application .This code is part of CMainFrame class in a fucntion .When the function returns TRUE ,the application crashes .Help me out please

    M C 2 Replies Last reply
    0
    • R RaajaOfSelf

      I have some problem in my code .Due to my inexpereicne iam not able to solve it . HANDLE hFile; LPWIN32_FIND_DATA FileData; hFile=FindFirstFile(str,FileData); if(hFile==INVALID_HANDLE_VALUE) { FindClose(hFile); return FALSE; } else { FindClose(hFile); AfxMessageBox("File Does Exists "); return TRUE; } This is a MFC application .This code is part of CMainFrame class in a fucntion .When the function returns TRUE ,the application crashes .Help me out please

      M Offline
      M Offline
      Martyn Pearson
      wrote on last edited by
      #2

      The answer doesn't immediately spring to mind but, two points which may help... 1) I'm not sure that you have to call FindClose() when the handle returned is INVALID_HANDLE_VALUE. 2) Have you tried using the access() function declared in . This can be used to check for the existence of a file too.

      1 Reply Last reply
      0
      • R RaajaOfSelf

        I have some problem in my code .Due to my inexpereicne iam not able to solve it . HANDLE hFile; LPWIN32_FIND_DATA FileData; hFile=FindFirstFile(str,FileData); if(hFile==INVALID_HANDLE_VALUE) { FindClose(hFile); return FALSE; } else { FindClose(hFile); AfxMessageBox("File Does Exists "); return TRUE; } This is a MFC application .This code is part of CMainFrame class in a fucntion .When the function returns TRUE ,the application crashes .Help me out please

        C Offline
        C Offline
        csc
        wrote on last edited by
        #3

        hi there if you only want to check if the file is existing you can do that like that : CString csMyFile = "c:\\temp\\some.file.dat"; CFileStatus statusFile; BOOL bExists = CFile::GetStatus( csMyFile, statusFile ); return( bExists ); But i guess the crash is a result of that : HANDLE hFile; LPWIN32_FIND_DATA FileData; hFile=FindFirstFile(str,FileData); You should not only pass a pointer to FindFirstFile(..). It must be a pointer to an existing WIN32_FIND_DATA-struct !!! If you only pass a pointer to "SomeWhereInMemory" and FindFirstFile starts writing data about an existing file ... it writes to "SomeWhereInMemory" .... and that no good idea ! look at the VC++ MSDN-Help about FindFirstFile : pFindFileData : Pointer to the WIN32_FIND_DATA structure that receives information about the found file ... so write it that way : WIN32_FIND_DATA FileData; hFile=FindFirstFile(str,&FileData); and i think it will work .... (without GPF).

        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