Errors on Finding a File
Sep 25, 2011 at 4:37am UTC
I'm running this code to find any file that was written to the hard drive recently. However; I've gotten a few errors that I can't seem to lick. Here is the code, followed by the errors. Windows 7 Any help is appreciated. Thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <string>
#include <vector>
#include <windows.h>
#include <time.h>
#include <map>
#include <tchar.h>
int GetFileList(const wchar_t *searchkey, std::map<std::wstring, std::wstring> &map)
{
WIN32_FIND_DATA fd;
HANDLE h = FindFirstFile(searchkey,&fd);
if (h == INVALID_HANDLE_VALUE)
{
return 0; // no files found
}
while (1)
{
wchar_t buf[128];
FILETIME ft = fd.ftLastWriteTime;
SYSTEMTIME sysTime;
FileTimeToSystemTime(&ft, &sysTime);
wsprintf(buf, L"%d-%02d-%02d" ,sysTime.wYear, sysTime.wMonth, sysTime.wDay);
map[fd.cFileName] = buf;
if (FindNextFile(h, &fd) == FALSE)
break ;
}
return map.size();
}
void main()
{
std::map<std::wstring, std::wstring> map;
int count = GetFileList(L"c:\\*.*" , map);
// Using const_iterator
for (std::map<std::wstring, std::wstring>::const_iterator it = map.begin();
it != map.end(); ++it)
{
MessageBox(it->first.c_str());
MessageBox(it->second.c_str());
}
}
The Errors:
1 error C2660: 'MessageBoxW' : function does not take 1 arguments
2 error C2660: 'MessageBoxW' : function does not take 1 arguments
3 IntelliSense: argument of type "const wchar_t *" is incompatible
with parameter of type "HWND"
4 IntelliSense: too few arguments in function call
5 IntelliSense: argument of type "const wchar_t *" is incompatible
with parameter of type "HWND"
6 IntelliSense: too few arguments in function call
Sep 25, 2011 at 5:31am UTC
The error is just what it says.
MessageBox takes 4 parameters, not 1:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx
What you probably want is this:
1 2 3 4 5 6
MessageBoxW( // note: MessageBoxW since you're giving it a wchar string and not a TCHAR string
NULL, // NULL for the parent window
it->first.c_str(), // the text in the box
L"Whatever" , // the title/caption for the box
MB_OK // just an "OK" button for the UI
);
Sep 25, 2011 at 7:15am UTC
Great! Works most prefectly! Thank you!
Topic archived. No new replies allowed.