FindFirstFile()返回的是INVALID_HANDLE_VALUE
用的是vs2008,不知问题出在哪。。
代码如下:
#include <windows.h> 
#include <iostream> 
using namespace std;int main()
{
    HANDLE hFind;
    WIN32_FIND_DATA FindData;    cout << "A very basic FindFirst/Next demo.\n" << endl;// Find the first file    hFind = FindFirstFile(reinterpret_cast<LPTSTR>("C:\\Windows\\*.exe"), &FindData);
    cout << FindData.cFileName << endl;// Look for more    while (FindNextFile(hFind, &FindData))
    {
        cout << FindData.cFileName << endl;
    }// Close the file handle    FindClose(hFind);    return 0;
}

解决方案 »

  1.   

    vs2008用的是UNICODE,去掉UNICODE选项,或者改下代码
    #include <windows.h> 
    #include <iostream> 
    using namespace std;int _tmain(int argc, _TCHAR* argv[])
    {
    HANDLE hFind; 
    WIN32_FIND_DATAA FindData;  cout << "A very basic FindFirst/Next demo.\n" << endl;  // Find the first file  hFind = FindFirstFileA(reinterpret_cast <LPSTR>("C:\\Windows\\*.exe"), &FindData); 
    cout << FindData.cFileName << endl;  // Look for more  while (FindNextFileA(hFind, &FindData)) 

    cout << FindData.cFileName << endl; 
    }  // Close the file handle  FindClose(hFind);  return 0;
    }