1
没有工作,我有这样的代码在我的程序:上市文件:c
char * choosePic(const char * dir)
{
WIN32_FIND_DATA fdFile;
HANDLE hFind = null;
char sPath[2048];
sprintf(sPath, "%s\\*.*", dir);
if ((hFind = FindFirstFile((LPCWSTR) sPath, &fdFile)) == INVALID_HANDLE_VALUE)
{
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
printf("File not found");
}
else
{
printf("Error with path")
}
FindClose(hFind);
return NULL;
}
do
{
if (strcmp((char *) fdFile.cFileName, "*.*") != 0 && strcmp((char *) fdFile.cFileName, ".." != 0)
{
printf("%s %s", sPath, dir);
}
} while (FindNextFile(hFind, &fdFile));
FindClose(hFind);
}
我给这个函数的路径,choosePic("C:\\Windows")
,我只得到:
> Error with path
我尝试了很多东西,甚至使用管理员权限运行。 没有用。
哪些错误代码,您在Win32 API中得到些什么? – NPE 2014-10-05 06:45:41
'(LPCWSTR)sPath' - sPath不是一个宽字符串,所以将它转换为一个不会使任何工作。如果您正在编译Unicode,请正确使用它,或切换到多字节应用程序。 – 2014-10-05 06:47:11
我不需要Unicode。那么我应该如何处理sPath?因为删除演员给出了一个错误。错误代码是3. – Shtut 2014-10-05 07:00:43