title: Call function FindNextFile throw access violation exception
body: <p>I write a c program using Win32 API <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa364428%28v=vs.85%29.aspx" rel="nofollow">FindNextFile</a> to find files<p></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;tchar.h&gt;
  #include&lt;windows.h&gt;
  
  int _tmain(int argc, TCHAR *argv[])
  {
      HANDLE hNextFile;
      WIN32_FIND_DATA findFileData;
      LPCTSTR fileName = argv[1]; //input argument "C:\test\file*.txt"
  
      hNextFile = FindFirstFile(fileName, &amp;findFileData);
  
      while(hNextFile != INVALID_HANDLE_VALUE)
      {
          printf("long name: %s\t8dot3 name: %s\n", findFileData.cFileName, findFileData.cAlternateFileName);
          hNextFile = FindNextFile(fileName, &amp;findFileData); //Unhandled exception here!
      }
      printf("%s", GetLastError());
      return 0;
  }
  </code></pre>
  
  <p>When call FindNextFile firstly, it throw exception.
  Exception info:<p></p>
  
  <blockquote>
    <p>Unhandled exception at 0x77178dc9 in findfile.exe: 0xC0000005: Access
    violation writing location 0x005c0080.</p>
  </blockquote>
  
  <p>Could you give me some suggestions?<p>
  Thanks in advance.<p></p>
  
  <hr>
  
  <p>I have modified my code like this, it works fine. Thanks for Pierre's explain.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;tchar.h&gt;
  #include&lt;windows.h&gt;
  
  int _tmain(int argc, TCHAR *argv[])
  {
      HANDLE hNextFind;
      WIN32_FIND_DATA findFileData;
      LPCTSTR fileName = argv[1];
      BOOL result = TRUE;
  
      if((hNextFind = FindFirstFile(fileName, &amp;findFileData)) == INVALID_HANDLE_VALUE)
          return 1;
  
      while(result)
      {
          _tprintf(TEXT("long name: %s\t8dot3 name: %s\n"), findFileData.cFileName, findFileData.cAlternateFileName);
          result = FindNextFile(hNextFind, &amp;findFileData);
      }
      FindClose(hNextFind);
      return 0;
  }
  </code></pre>