I keep getting compile errors with the line at the bottom
hFind = FindFirstFile(fileFilter.c_str()), &FindFileData);
The compiler keeps throwing error C2664 back at me, : cannot convert argument 1 from 'const char *' to 'LPCWSTR'
How do I create a LPCWSTR to a std::string to pass to into FindFirstFile?
Zhe section of code is for reference.
The actual code follows below.
using namespace std;
void GetFileListing(string directory, string fileFilter, bool recursively = true)
{
if (recursively)
GetFileListing(directory, fileFilter, false);
directory += "\\";
WIN32_FIND_DATA FindFileData;
HANDLE hFind ;
string filter = directory + (recursively ? "*" : fileFilter);
string Full_Name;
string Part_Name;
// the line causing the compile error
hFind = FindFirstFile(fileFilter.c_str()), &FindFileData);
The WinAPI data types are lovely short abbreviations.
LPCWSTRis short for:As such it is a pointer (long pointers are history) to the first character of a const wide string (
const wchar_t*), meaning you need to usestd::wstring::c_str()instead ofstd::string::c_str().Side note: just be sure to
#define UNICODEeverywhere you use the WinAPI, otherwise you'll get other errors about conversion toLPCSTR. Alternatively, explicitly use theWversions of the WinAPI functions where they exist.