DWORD和unsigned int

时间:2011-10-02 18:42:49

标签: c++ windows

我收到此错误但无法更正。任何帮助表示赞赏。谢谢。 错误C2440:'=':无法从'DWORD *'转换为'unsigned int' IntelliSense:“DWORD *”类型的值无法分配给“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);
}
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;
}

它就在这条线上......

1 个答案:

答案 0 :(得分:5)

错误在于:

curTime = ((_int64) &ftNow.dwHighDateTime << 32) + &ftNow.dwLowDateTime;

dwHighDateTimedwLowDateTime已经是int类型。然而你正在接受他们的地址。因此,curTime的赋值变为指向int。

的指针

你想要的是这个:

curTime = ((_int64) ftNow.dwHighDateTime << 32) + ftNow.dwLowDateTime;

第二期:

curTimefileTime只有32位。你需要使它们成为64位整数。