Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ FindNextFile在64位Windows上失败?_C++_64 Bit_C++builder - Fatal编程技术网

C++ FindNextFile在64位Windows上失败?

C++ FindNextFile在64位Windows上失败?,c++,64-bit,c++builder,C++,64 Bit,C++builder,使用C++Builder 2007,FindFirstFile和FindNextFile函数似乎无法在64位版本的Vista和XP上找到某些文件。我的测试应用程序是32位的 如果我使用它们遍历文件夹C:\Windows\System32\Drivers,它们只能找到少量文件,尽管在命令提示符下发出dir命令时有185个文件。使用相同的示例代码列出32位XP版本上的所有文件 下面是一个小示例程序: int main(int argc, char* argv[]) { HANDLE hFind;

使用C++Builder 2007,FindFirstFile和FindNextFile函数似乎无法在64位版本的Vista和XP上找到某些文件。我的测试应用程序是32位的

如果我使用它们遍历文件夹C:\Windows\System32\Drivers,它们只能找到少量文件,尽管在命令提示符下发出dir命令时有185个文件。使用相同的示例代码列出32位XP版本上的所有文件

下面是一个小示例程序:

int main(int argc, char* argv[])
{
  HANDLE hFind;
  WIN32_FIND_DATA FindData;
  int ErrorCode;
  bool cont = true;

  cout << "FindFirst/Next demo." << endl << endl;

  hFind = FindFirstFile("*.*", &FindData);
  if(hFind == INVALID_HANDLE_VALUE)
  {
    ErrorCode = GetLastError();
    if (ErrorCode == ERROR_FILE_NOT_FOUND)
    {
      cout << "There are no files matching that path/mask\n" << endl;
    }
    else
    {
      cout << "FindFirstFile() returned error code " << ErrorCode << endl;
    }
    cont = false;
  }
  else
  {
    cout << FindData.cFileName << endl;
  }

  if (cont)
  {
    while (FindNextFile(hFind, &FindData))
    {
      cout << FindData.cFileName << endl;
    }

    ErrorCode = GetLastError();
    if (ErrorCode == ERROR_NO_MORE_FILES)
    {
      cout << endl << "All files logged." << endl;
    }
    else
    {
      cout << "FindNextFile() returned error code " << ErrorCode << endl;
    }

    if (!FindClose(hFind))
    {
      ErrorCode = GetLastError();
      cout << "FindClose() returned error code " << ErrorCode << endl;
    }
  }
  return 0;
}
同一系统上的dir命令返回以下内容:

C:\WINDOWS\system32\drivers>t:\Project1.exe
FindFirst/Next demo.

.
..
AsIO.sys
ASUSHWIO.SYS
hfile.txt
raspti.zip
stcp2v30.sys
truecrypt.sys

All files logged.
C:\WINDOWS\system32\drivers>dir/p
 Volume in drive C has no label.
 Volume Serial Number is E8E1-0F1E

 Directory of C:\WINDOWS\system32\drivers

16-09-2008  23:12    <DIR>          .
16-09-2008  23:12    <DIR>          ..
17-02-2007  00:02            80.384 1394bus.sys
16-09-2008  23:12             9.453 a.txt
17-02-2007  00:02           322.560 acpi.sys
29-03-2006  14:00            18.432 acpiec.sys
24-03-2005  17:11           188.928 aec.sys
21-06-2008  15:07           291.840 afd.sys
29-03-2006  14:00            51.712 amdk8.sys
17-02-2007  00:03           111.104 arp1394.sys
08-05-2006  20:19             8.192 ASACPI.sys
29-03-2006  14:00            25.088 asyncmac.sys
17-02-2007  00:03           150.016 atapi.sys
17-02-2007  00:03           106.496 atmarpc.sys
29-03-2006  14:00            57.344 atmepvc.sys
17-02-2007  00:03            91.648 atmlane.sys
17-02-2007  00:03           569.856 atmuni.sys
24-03-2005  19:12             5.632 audstub.sys
29-03-2006  14:00             6.144 beep.sys
Press any key to continue . . .
etc.
C:\WINDOWS\system32\drivers>dir/p
驱动器C中的卷没有标签。
卷序列号为E8E1-0F1E
C:\WINDOWS\system32\drivers目录
16-09-2008  23:12              .
16-09-2008  23:12              ..
17-02-2007 00:02 80.384 1394bus.sys
16-09-2008 23:12 9.453 a.txt
17-02-2007 00:02 322.560 acpi.sys
29-03-2006 14:00 18.432 acpiec.sys
24-03-2005 17:11 188.928 aec.sys
21-06-2008 15:07 291.840 afd.sys
29-03-2006 14:00 51.712 amdk8.sys
17-02-2007 00:03 111.104 arp1394.sys
08-05-2006 20:19 8.192 ASACPI.sys
29-03-2006 14:00 25.088 asyncmac.sys
17-02-2007 00:03 150.016 atapi.sys
17-02-2007 00:03 106.496 atmarpc.sys
29-03-2006 14:00 57.344 atmepvc.sys
17-02-2007 00:03 91.648 atmlane.sys
17-02-2007 00:03 569.856 atmuni.sys
24-03-2005 19:12 5.632 audsub.sys
29-03-2006 14:00 6.144哔哔声系统
按任意键继续。
等
我很困惑。这是什么原因


Brian

您确定它与dir命令在同一目录中查找吗?他们似乎没有任何共同的文件

此外,这不是问题所在,但“所有文件”的正确通配符是*


**表示“名称中至少包含一个的所有文件”

是否正在进行重定向?请参阅Wow64DisableWow64FsRedirection上的备注编译时是否有任何警告

您是否已为此特定测试打开所有警告(因为它不工作)


确保首先解决警告。

示例代码没有问题。我还有一个应用程序也失败了,是用Delphi编写的。我想我是根据克里斯关于重定向的回答找到答案的: 我在MSDN上找到了这个:

如果正在编写32位应用程序以列出目录中的所有文件,并且该应用程序可能在64位计算机上运行,则应在调用FindFirstFile之前调用Wow64DisableWow64FsRedirectionfunction,并在最后一次调用FindTextFile之后调用Wow64RevertWow64FsRedirection。有关更多信息,请参阅文件系统重定向器

我必须更新我的代码,因为:-)

明白了:

当32位应用程序从64位操作系统上的其中一个文件夹中读取时:

%windir%\system32\catroot
%windir%\system32\catroot2
%windir%\system32\drivers\etc
%windir%\system32\logfiles
%windir%\system32\spool 
Windows实际上列出了以下内容:

%windir%\SysWOW64\catroot
%windir%\SysWOW64\catroot2
%windir%\SysWOW64\drivers\etc
%windir%\SysWOW64\logfiles
%windir%\SysWOW64\spool 
谢谢你的投入,克里斯,这帮助我了解了到底发生了什么


编辑:也谢谢Ludvig:-)

C:\Windows\System64\Drivers中的文件是什么?我在C:\Windows\System32\Drivers中列出了这些文件,但实际上是在C:\Windows\SysWOW64\Drivers:-)中得到的文件