static void GetFilesFromDir(std::string dir, std::vector<std::string>& items)
{
WIN32_FIND_DATA findData;
HANDLE hFind=FindFirstFile((dir+"\\*").c_str(), &findData); //1 error
do
{
if(hFind != INVALID_HANDLE_VALUE)
{
std::string sFileName = findData.cFileName; //2 error
LPCSTR lp(sFileName.c_str());
if(sFileName == "." || sFileName == "..")
{} //do nothing
else if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
GetFilesFromDir(dir+"\\"+sFileName, items);
else
items.push_back(dir+"\\"+sFileName);
}
} while (FindNextFile(hFind, &findData));
}
所以这是我刚刚从另一个项目复制到新项目的简单函数。它会无缘无故地抛出错误,尤其是因为它在其他项目中也有效......
1>c:\users\prog\documents\visual studio 2010\projects\vampire stealth\vampire stealth\smallfunctions.h(22): error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\prog\documents\visual studio 2010\projects\vampire stealth\vampire stealth\smallfunctions.h(27): error C2440: 'initializing' : cannot convert from 'WCHAR [260]' to 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
有人对出了什么问题有任何想法吗?我对此一无所知。