BOOL DelInetTempFiles()
{
BOOL bResult = FALSE;
BOOL bDone = FALSE;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;
DWORD dwTrySize, dwEntrySize = 4096; //内存大小
HANDLE hCacheDir = NULL;
DWORD dwError = ERROR_INSUFFICIENT_BUFFER;
do
{
switch (dwError)
{
case ERROR_INSUFFICIENT_BUFFER:
delete [] lpCacheEntry;
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];
lpCacheEntry->dwStructSize = dwEntrySize;
dwTrySize = dwEntrySize;
BOOL bSuccess;
if (hCacheDir == NULL)
bSuccess = (hCacheDir= FindFirstUrlCacheEntry(NULL, lpCacheEntry,&dwTrySize)) != NULL; //从Internet的高速缓存中找到特定入口
else //查找下一个缓存入口
bSuccess = FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize);
if (bSuccess)
dwError = ERROR_SUCCESS;
else
{
dwError = GetLastError();
dwEntrySize = dwTrySize; // use new size returned
}
break;
case ERROR_NO_MORE_ITEMS: //没有可删除的项目
bDone = TRUE;
bResult = TRUE;
break;
case ERROR_SUCCESS:
//不删除cookie
if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))
DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName); //删除Cache中指定的源文件名
// 查找下一个缓存入口
dwTrySize = dwEntrySize;
if (FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize))
dwError = ERROR_SUCCESS;
else
{
dwError = GetLastError();
dwEntrySize = dwTrySize; // use new size returned
}
break;
default:
bDone = TRUE;
break;
}
if (bDone)
{
delete [] lpCacheEntry;
if (hCacheDir)
FindCloseUrlCache(hCacheDir); //关闭指定的缓存枚举句柄
}
} while (!bDone);
return bResult;
}
{
BOOL bResult = FALSE;
BOOL bDone = FALSE;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;
DWORD dwTrySize, dwEntrySize = 4096; //内存大小
HANDLE hCacheDir = NULL;
DWORD dwError = ERROR_INSUFFICIENT_BUFFER;
do
{
switch (dwError)
{
case ERROR_INSUFFICIENT_BUFFER:
delete [] lpCacheEntry;
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];
lpCacheEntry->dwStructSize = dwEntrySize;
dwTrySize = dwEntrySize;
BOOL bSuccess;
if (hCacheDir == NULL)
bSuccess = (hCacheDir= FindFirstUrlCacheEntry(NULL, lpCacheEntry,&dwTrySize)) != NULL; //从Internet的高速缓存中找到特定入口
else //查找下一个缓存入口
bSuccess = FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize);
if (bSuccess)
dwError = ERROR_SUCCESS;
else
{
dwError = GetLastError();
dwEntrySize = dwTrySize; // use new size returned
}
break;
case ERROR_NO_MORE_ITEMS: //没有可删除的项目
bDone = TRUE;
bResult = TRUE;
break;
case ERROR_SUCCESS:
//不删除cookie
if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))
DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName); //删除Cache中指定的源文件名
// 查找下一个缓存入口
dwTrySize = dwEntrySize;
if (FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize))
dwError = ERROR_SUCCESS;
else
{
dwError = GetLastError();
dwEntrySize = dwTrySize; // use new size returned
}
break;
default:
bDone = TRUE;
break;
}
if (bDone)
{
delete [] lpCacheEntry;
if (hCacheDir)
FindCloseUrlCache(hCacheDir); //关闭指定的缓存枚举句柄
}
} while (!bDone);
return bResult;
}