0

我有一个列出所有目录的 C++ 应用程序,即您的 HDD 树。我什至可以进入这些目录查看里面有什么,但是当我想在计算机上打开另一个用户的目录时会遇到问题。我无权去那里,它应该像在 Windows XP/Vista/7 中那样声明;相反,我收到一个错误,我的应用程序终止。

我该如何处理这个,用FILE_ATTRIBUTE_,或其他东西,所以当用户点击一个他不能进入的目录时,我的应用程序不会崩溃?它应该只是告诉他访问被拒绝。

我的应用程序是在 VS 2010 中制作的。

4

2 回答 2

0

All you need to do is check the return value from FindFirstFile (or whatever function you use to look inside a directory) and give the user a warning instead of further processing.

The crash probably comes from trying to use the result buffer after the function failed. When the function fails, you should not look at what's in the result buffer or pass it to any other functions (like FindNextFile), instead assume it is total garbage.

于 2013-07-14T21:11:12.803 回答
0

预先检测用户无法进入的目录,并且不会将它们呈现给用户界面。

于 2013-07-14T21:06:53.640 回答