一、主要用到以下几个API:
1、FindFirstUrlCacheEntry
2、FindNextUrlCacheEntry
3、FindCloseUrlCache
下面的内容摘自MSDN:
-------------------------------------------------------------------------------------------------------------------------------------------------------
Client
|
Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.
|
Server
|
Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
|
Version
|
Requires Internet Explorer 3.0 or later.
|
Header
|
Declared in Wininet.h.
|
Library
|
Use Wininet.lib.
|
DLL
|
Requires Wininet.dll.
|
Unicode
|
Implemented as FindFirstUrlCacheEntryW (Unicode) and FindFirstUrlCacheEntryA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
|
Return code
|
Description
|
ERROR_INSUFFICIENT_BUFFER
|
The size of lpNextCacheEntryInfo as specified by lpdwNextCacheEntryInfoBufferSize is not sufficient to contain all the information. The value returned in lpdwNextCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information.
|
ERROR_NO_MORE_ITEMS
|
The enumeration completed.
|
Client
|
Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.
|
Server
|
Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
|
Version
|
Requires Internet Explorer 3.0 or later.
|
Header
|
Declared in Wininet.h.
|
Library
|
Use Wininet.lib.
|
DLL
|
Requires Wininet.dll.
|
Unicode
|
Implemented as FindNextUrlCacheEntryW (Unicode) and FindNextUrlCacheEntryA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
|
FindCloseUrlCache
This function closes the specified cache enumeration handle.
BOOL FindCloseUrlCache( HANDLE hEnumHandle );
Parameters
hEnumHandle
[in] Handle returned by a previous call to the FindFirstUrlCacheEntry function.
Return Values
Returns TRUE if successful, or FALSE otherwise.
Requirements
OS Versions: Windows CE 2.12 and later.
Header: Wininet.h.
Link Library: Wininet.lib.
DeleteUrlCacheEntry
This function removes the file associated with the source name from the cache, if the file exists.
BOOL DeleteUrlCacheEntry( LPCTSTR lpszUrlName );
Parameters
lpszUrlName
[in] Address of a string variable that contains the cache entry source name. The name string must be unique and cannot contain escape characters.
Return Values
Returns TRUE if successful, or FALSE otherwise.
Requirements
OS Versions: Windows CE 2.12 and later.
Header: Wininet.h.
Link Library: Wininet.lib.
DWORD dwStructSize;
LPTSTR lpszSourceUrlName;
LPTSTR lpszLocalFileName;
DWORD CacheEntryType;
DWORD dwUseCount;
DWORD dwHitRate;
DWORD dwSizeLow;
DWORD dwSizeHigh;
FILETIME LastModifiedTime;
FILETIME ExpireTime;
FILETIME LastAccessTime;
FILETIME LastSyncTime;
LPBYTE lpHeaderInfo;
DWORD dwHeaderInfoSize;
LPTSTR lpszFileExtension;
union {
DWORD dwReserved;
DWORD dwExemptDelta;
}; } INTERNET_CACHE_ENTRY_INFO,
*LPINTERNET_CACHE_ENTRY_INFO;
Value
|
Meaning
|
EDITED_CACHE_ENTRY
|
Cache entry file that has been edited externally. This cache entry type is exempt from scavenging.
|
SPARSE_CACHE_ENTRY
|
Partial response cache entry.
|
STICKY_CACHE_ENTRY
|
Sticky cache entry that is exempt from scavenging for the amount of time specified by dwExemptDelta. The default value set by CommitUrlCacheEntry is one day.
|
TRACK_OFFLINE_CACHE_ENTRY
|
Not currently implemented.
|
TRACK_ONLINE_CACHE_ENTRY
|
Not currently implemented.
|
Value
|
Meaning
|
COOKIE_CACHE_ENTRY
|
Cookie cache entry.
|
NORMAL_CACHE_ENTRY
|
Normal cache entry; can be deleted to recover space for new entries.
|
URLHISTORY_CACHE_ENTRY
|
Visited link cache entry.
|
Client
|
Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.
|
Server
|
Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
|
Version
|
Requires Internet Explorer 3.0 or later.
|
Header
|
Declared in Wininet.h.
|
Unicode
|
Implemented as INTERNET_CACHE_ENTRY_INFOW (Unicode) and INTERNET_CACHE_ENTRY_INFOA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
|
#include < windows.h >
#include < wininet.h >
// 获取IE上网缓存信息。如Cookie信息、Visited网址信息等
BOOL GetIECache()
... {
int count = 0;
HANDLE hCacheEnumHandle = NULL;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;
DWORD dwSize = 4096;
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwSize];
lpCacheEntry->dwStructSize = dwSize;
// URL search pattern (1st parameter) options are: NULL ("*.*"), "cookie:",
// or "visited:".
hCacheEnumHandle = FindFirstUrlCacheEntry(
"visited:", lpCacheEntry, &dwSize);
if(hCacheEnumHandle != NULL)
...{
printf(" %s ", lpCacheEntry->lpszSourceUrlName);
}
else
...{
switch(GetLastError())
...{
case ERROR_INSUFFICIENT_BUFFER:
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwSize];
lpCacheEntry->dwStructSize = dwSize;
// Repeat first step search with adjusted buffer, exit if not
// found again (in practice one buffer's size adustment is
// always OK).
hCacheEnumHandle = FindFirstUrlCacheEntry("visited:", lpCacheEntry,
&dwSize);
if (hCacheEnumHandle != NULL)
...{
count++;
printf(" %d: %s ", count, lpCacheEntry->lpszSourceUrlName);
break;
}
else
...{
// FindFirstUrlCacheEntry fails again, return.
return FALSE;
}
default:
...{
FindCloseUrlCache(hCacheEnumHandle);
return FALSE;
}
}
}
do
...{
// Notice that return values of FindNextUrlCacheEntry (BOOL) and
// FindFirstUrlCacheEntry (HANDLE) are different.
if (FindNextUrlCacheEntry(hCacheEnumHandle, lpCacheEntry, &dwSize))
...{
count++;
printf(" %d: %s ", count, lpCacheEntry->lpszSourceUrlName);
}
else
...{
switch(GetLastError())
...{
case ERROR_INSUFFICIENT_BUFFER:
lpCacheEntry =
(LPINTERNET_CACHE_ENTRY_INFO) new char[dwSize];
lpCacheEntry->dwStructSize = dwSize;
// Repeat next step search with adjusted buffer, exit if
// error comes up again ((in practice one buffer's size
// adustment is always OK).
if (FindNextUrlCacheEntry(hCacheEnumHandle, lpCacheEntry,
&dwSize))
...{
count++;
printf(" %d: %s ", count, lpCacheEntry->lpszSourceUrlName);
break;
}
else
...{
// FindFirstUrlCacheEntry fails again, return.
FindCloseUrlCache(hCacheEnumHandle);
return FALSE;
}
break;
case ERROR_NO_MORE_ITEMS:
FindCloseUrlCache(hCacheEnumHandle);
return TRUE;
default:
FindCloseUrlCache(hCacheEnumHandle);
return FALSE;
}
}
} while (TRUE);
}