Code is at bottom of post. The thing I want to do is make a download class which downloads a URL and places it somewhere. It should be uses for html source as well as binary files, so I'm using URLDownloadToFile from UrlMon.h. The thing is that this will keep a copy in the cache of internet explorer, and I want that when I download something, I always get the newest version, and that I don't have alot of wasted HDD space in those cache folders after a while. Calling DeleteUrlCacheEntry() after the download works like a charm in most cases, but I've been doing some testing and sometimes I get an ERROR_SHARING_VIOLATION. I'm getting these when I download an MP3 file, about 3MB in size and it has tags which state the artists and such. However I don't get them on another downloaded MP3 file which is about 40MB in size and doesn't has those tags. I also have been testing with html files and rar files of various sizes, and these also don't cause any error. Further more no exporer browsers or instances of internet explorer are running at the moment of getting the error.
So I'm looking for a reason why this is happening and a solution to it.
EDIt: some further testing has brought to my attention that the same mp3 file but from another server doesn't have the error. So the answer must be in this direction.
Code:
DWORD Download::DownloadProc()
{
tstring fullsavepath = m_Savepath + m_Filename;
HRESULT hr = URLDownloadToFile(NULL,m_Url.c_str(),fullsavepath.c_str(),0,&m_StatusCallback);
if (DeleteUrlCacheEntry(m_Url.c_str()) == FALSE)
{
DWORD err = GetLastError();
if (err != ERROR_ACCESS_DENIED && err != ERROR_FILE_NOT_FOUND)
{
tstringstream buf;
buf << _T("DeleteUrlCacheEntry() returned error code ") << err << endl;
OutputDebugString(buf.str());
}
}
if (hr != S_OK)
DeleteFile(fullsavepath.c_str());
m_IsFinished = true;
CloseHandle(m_hThread);
return 0;
}