DWORD and unsigned int
I'm getting this error and can't correct it. Any help is appreciated. Thanks. error C2440: '=' : cannot convert from 'DWORD *' to 'unsigned int' IntelliSense: a value of type "DWORD *" cannot be assigned to an entity of type "unsigned int"
using namespace std;
typedef vector<WIN32_FIND_DATA> tFoundFilesVector;
std::wstring LastWriteTime;
int getFileList(wstring filespec, tFoundFilesVector &foundFiles)
{
WIN32_FIND_DATA findData;
HANDLE h;
int validResult=true;
int numFoundFiles = 0;
h = FindFirstFile(filespec.c_str(), &findData);
if (h == INVALID_HANDLE_VALUE)
return 0;
while (validResult)
{
numFoundFiles++;
foundFiles.push_back(findData);
validResult = FindNextFile(h, &findData);
开发者_如何学JAVA}
return numFoundFiles;
}
void showFileAge(tFoundFilesVector &fileList)
{
unsigned int fileTime,curTime, age;
tFoundFilesVector::iterator iter;
FILETIME ftNow;
__int64 nFileSize;
LARGE_INTEGER li;
li.LowPart = ftNow.dwLowDateTime;
li.HighPart = ftNow.dwHighDateTime;
CoFileTimeNow(&ftNow);
curTime = ((_int64) &ftNow.dwHighDateTime << 32) + &ftNow.dwLowDateTime;
for (iter=fileList.begin(); iter<fileList.end(); iter++)
{
fileTime = ((_int64)iter->ftLastWriteTime.dwHighDateTime << 32) + iter- >ftLastWriteTime.dwLowDateTime;
age = curTime - fileTime;
cout << "FILE: '" << iter->cFileName << "', AGE: " << (INT64)age/10000000UL << " seconds" << endl;
}
}
int main()
{
string fileSpec = "*.*";
tFoundFilesVector foundFiles;
tFoundFilesVector::iterator iter;
int foundCount = 0;
getFileList(L"*.c??", foundFiles);
getFileList(L"*.h", foundFiles);
foundCount = foundFiles.size();
if (foundCount)
{
cout << "Found "<<foundCount<<" matching files.\n";
showFileAge(foundFiles);
}
return 0;
}
Its on this line.....
The error is here:
curTime = ((_int64) &ftNow.dwHighDateTime << 32) + &ftNow.dwLowDateTime;
dwHighDateTime
and dwLowDateTime
are already of type int
. Yet you are taking the address of them. Therefore the assignment to curTime
becomes pointer to int.
What you want is this:
curTime = ((_int64) ftNow.dwHighDateTime << 32) + ftNow.dwLowDateTime;
Second Issue:
curTime
and fileTime
are only 32-bits. You need to make them 64-bit integers.
精彩评论