I did not write the code below, it's open source and no longer supported. I do need to make a few changes to it so I installed VC++ Express 2010 and I've managed to work out most of the problems, and the application was actually written for Windows to begin with so while it's been hair-pulling but reasonably difficult, I am making some progress.
I am stuck on one conversion and I haven't quite gotten a handle on VC++ 2010 type conversions, but here is the code giving me my last headache...
path is std::string and cFileName is WCHAR. I beleive I was successful in converting path to WCHAR, but then mEntries.push_back had a problem with it. What I beleive I need to do is convert cFileName to a string, and I have searched and tried numerous different ways to do it but I'm either getting the syntax wrong or it's not working in VC++ or I'm completely missing something else.
It would be nice to know why it does not work and why there are soooo many different "types" of strings (I write SQL Scripts, this is ridiculous) but at this point, I just need help making it work.
// Add files matching file spec to listing, returning number added. Each
// filename is prepended with its path, if one was supplied in file spec.
unsigned int DirList :: Add( const string & fspec ) {
// save path, if any
STRPOS lastslash = fspec.find_last_of( "\\/");
string path = lastslash == STRNPOS ? "" : fspec.substr( 0, lastslash + 1 );
unsigned int count = 0;
WIN32_FIND_DATA fd;
HANDLE h = FindFirstFile( LPCWSTR(fspec.c_str()), & fd );
if ( h == INVALID_HANDLE_VALUE ) {
return count;
}
do {
mEntries.push_back(
new WinDirEntry(
path + fd.cFileName, // add path back on
fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
)
);
count++;
} while( FindNextFile( h, & fd ) );
FindClose( h );
return count;
}
The Error message is:
error C2782: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(std::basic_string<_Elem,_Traits,_Alloc> &&,const _Elem *)' : template parameter '_Elem' is ambiguous
1> ...\microsoft visual studio 10.0\vc\include\string(143) : see declaration of 'std::operator +'
1> could be 'WCHAR'
1> or 'char'
error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(std::basic_string<_Elem,_Traits,_Alloc> &&,std::basic_string<_Elem,_Traits,_Alloc> &&)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &&' from 'WCHAR [260]'
1> ...\microsoft visual studio 10.0\vc\include\string(109) : see declaration of 'std::operator +'
error C2676: binary '+' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator