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.
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)
buf << _T("DeleteUrlCacheEntry() returned error code ") << err << endl;
if (hr != S_OK)
m_IsFinished = true;