110,962
社区成员
发帖
与我相关
我的任务
分享
查询了API中FindFirstUrlCacheEntryEx方法的定义,后修改FindFirstUrlCacheEntryEx定义如下:
[DllImport("wininet.dll")]
//Starts a filtered enumeration of the Internet cache.
public static extern IntPtr FindFirstUrlCacheEntryEx(
//A pointer to a string that contains the source name pattern to search for.
//This parameter can only be set to "cookie:", "visited:", or NULL.
//Set this parameter to "cookie:" to enumerate the cookies
//or "visited:" to enumerate the URL History entries in the cache.
//If this parameter is NULL, FindFirstUrlCacheEntryEx returns all content entries in the cache.
string lpszUrlSearchPattern,
//Controls the enumeration. No flags are currently implemented; this parameter must be set to zero.
uint dwFlags,
//A bitmask indicating the type of cache entry and its properties.
//The cache entry types include:
//history entries (URLHISTORY_CACHE_ENTRY),
//cookie entries (COOKIE_CACHE_ENTRY),
//and normal cached content (NORMAL_CACHE_ENTRY).
uint dwFilter,
//ID of the cache group to be enumerated. Set this parameter to zero to enumerate all entries that are not grouped.
Int64 GroupId,
//Pointer to a INTERNET_CACHE_ENTRY_INFO structure to receive the cache entry information.
IntPtr lpFirstCacheEntryInfo,
//Pointer to variable that indicates the size of the structure referenced by the lpFirstCacheEntryInfo parameter, in bytes.
ref uint lpdwFirstCacheEntryInfoBufferSize,
//This parameter is reserved and must be NULL.
IntPtr lpGroupAttributes,
//This parameter is reserved and must be NULL.
IntPtr pcbGroupAttributes,
//his parameter is reserved and must be NULL.
IntPtr lpReserved
);
FindNextUrlCacheEntryEx(vHandle, (IntPtr)null, ref vFirstCacheEntryInfoBufferSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
FindNextUrlCacheEntryEx(vHandle, vBuffer, ref vFirstCacheEntryInfoBufferSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public class INTERNET_CACHE_ENTRY_INFOW
{
public uint dwStructSize;
public string lpszSourceUrlName;
public string lpszLocalFileName;
public uint CacheEntryType;
public uint dwUseCount;
public uint dwHitRate;
public uint dwSizeLow;
public uint dwSizeHigh;
public FILETIME LastModifiedTime;
public FILETIME ExpireTime;
public FILETIME LastAccessTime;
public FILETIME LastSyncTime;
public IntPtr lpHeaderInfo;
public uint dwHeaderInfoSize;
public string lpszFileExtension;
public uint dwReserved; //union uint dwExemptDelta;
}
[DllImport("wininet.dll")]
public static extern IntPtr FindFirstUrlCacheEntryEx(
string lpszUrlSearchPattern,
uint dwFlags,
uint dwFilter,
Int64 GroupId,
IntPtr lpFirstCacheEntryInfo,
ref uint lpdwFirstCacheEntryInfoBufferSize,
Pointer lpGroupAttributes,
Pointer pcbGroupAttributes,
Pointer lpReserved
);
[DllImport("wininet.dll")]
public static extern bool FindCloseUrlCache(IntPtr hEnumHandle);
[DllImport("wininet.dll")]
public static extern bool FindNextUrlCacheEntryEx(
IntPtr hEnumHandle,
IntPtr lpFirstCacheEntryInfo,
ref uint lpdwFirstCacheEntryInfoBufferSize,
Pointer lpGroupAttributes,
Pointer pcbGroupAttributes,
Pointer lpReserved);
public uint NORMAL_CACHE_ENTRY = 0x00000001;
private void button1_Click(object sender, EventArgs e)
{
IntPtr vHandle;
INTERNET_CACHE_ENTRY_INFOW vInternetCacheEntryInfo = new INTERNET_CACHE_ENTRY_INFOW();
uint vFirstCacheEntryInfoBufferSize = 0;
FindFirstUrlCacheEntryEx(null, 0, NORMAL_CACHE_ENTRY, 0, (IntPtr)null,
ref vFirstCacheEntryInfoBufferSize, null, null, null);
IntPtr vBuffer = Marshal.AllocHGlobal((int)vFirstCacheEntryInfoBufferSize);
vHandle = FindFirstUrlCacheEntryEx(null, 0, NORMAL_CACHE_ENTRY, 0,
vBuffer, ref vFirstCacheEntryInfoBufferSize,
null, null, null);
while (vHandle != null)
{
Marshal.PtrToStructure(vBuffer, vInternetCacheEntryInfo);
richTextBox1.AppendText(vInternetCacheEntryInfo.lpszSourceUrlName + "\r\n");
Marshal.FreeCoTaskMem(vBuffer);
FindNextUrlCacheEntryEx(vHandle, (IntPtr)null, ref vFirstCacheEntryInfoBufferSize,
null, null, null);
vBuffer = Marshal.AllocHGlobal((int)vFirstCacheEntryInfoBufferSize);
if (!FindNextUrlCacheEntryEx(vHandle, vBuffer,
ref vFirstCacheEntryInfoBufferSize, null, null, null)) break;
}
Marshal.FreeCoTaskMem(vBuffer);
}
//-------接口方式-------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace IEHistory
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2)new UrlHistory();
IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls();
STATURL vSTATURL;
uint vFectched;
while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0)
{
richTextBox1.AppendText(string.Format("{0}:{1}\r\n",
vSTATURL.pwcsTitle, vSTATURL.pwcsUrl));
}
//vUrlHistoryStg2.ClearHistory();//清除历史
}
}
struct STATURL
{
public static uint SIZEOF_STATURL =
(uint)Marshal.SizeOf(typeof(STATURL));
public uint cbSize;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsUrl;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsTitle;
public FILETIME ftLastVisited,
ftLastUpdated,
ftExpires;
public uint dwFlags;
}
[ComImport, Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IEnumSTATURL
{
[PreserveSig]
uint Next(uint celt, out STATURL rgelt, out uint pceltFetched);
void Skip(uint celt);
void Reset();
void Clone(out IEnumSTATURL ppenum);
void SetFilter(
[MarshalAs(UnmanagedType.LPWStr)] string poszFilter,
uint dwFlags);
}
[ComImport, Guid("AFA0DC11-C313-11d0-831A-00C04FD5AE38"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IUrlHistoryStg2
{
#region IUrlHistoryStg methods
void AddUrl(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
[MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,
uint dwFlags);
void DeleteUrl(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
uint dwFlags);
void QueryUrl(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
uint dwFlags,
ref STATURL lpSTATURL);
void BindToObject(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
ref Guid riid,
[MarshalAs(UnmanagedType.IUnknown)] out object ppvOut);
IEnumSTATURL EnumUrls();
#endregion
void AddUrlAndNotify(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
[MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,
uint dwFlags,
[MarshalAs(UnmanagedType.Bool)] bool fWriteHistory,
[MarshalAs(UnmanagedType.IUnknown)] object /*IOleCommandTarget*/
poctNotify,
[MarshalAs(UnmanagedType.IUnknown)] object punkISFolder);
void ClearHistory();
}
[ComImport, Guid("3C374A40-BAE4-11CF-BF7D-00AA006946EE")]
class UrlHistory /* : IUrlHistoryStg[2] */ { }
}
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public class INTERNET_CACHE_ENTRY_INFOW
{
public uint dwStructSize;
public string lpszSourceUrlName;
public string lpszLocalFileName;
public uint CacheEntryType;
public uint dwUseCount;
public uint dwHitRate;
public uint dwSizeLow;
public uint dwSizeHigh;
public FILETIME LastModifiedTime;
public FILETIME ExpireTime;
public FILETIME LastAccessTime;
public FILETIME LastSyncTime;
public IntPtr lpHeaderInfo;
public uint dwHeaderInfoSize;
public string lpszFileExtension;
public uint dwReserved; //union uint dwExemptDelta;
}
[DllImport("wininet.dll")]
public static extern IntPtr FindFirstUrlCacheEntryEx(
string lpszUrlSearchPattern,
uint dwFlags,
uint dwFilter,
Int64 GroupId,
IntPtr lpFirstCacheEntryInfo,
ref uint lpdwFirstCacheEntryInfoBufferSize,
Pointer lpGroupAttributes,
Pointer pcbGroupAttributes,
Pointer lpReserved
);
[DllImport("wininet.dll")]
public static extern bool FindCloseUrlCache(IntPtr hEnumHandle);
[DllImport("wininet.dll")]
public static extern bool FindNextUrlCacheEntryEx(
IntPtr hEnumHandle,
IntPtr lpFirstCacheEntryInfo,
ref uint lpdwFirstCacheEntryInfoBufferSize,
Pointer lpGroupAttributes,
Pointer pcbGroupAttributes,
Pointer lpReserved);
public uint NORMAL_CACHE_ENTRY = 0x00000001;
private void button1_Click(object sender, EventArgs e)
{
IntPtr vHandle;
INTERNET_CACHE_ENTRY_INFOW vInternetCacheEntryInfo = new INTERNET_CACHE_ENTRY_INFOW();
uint vFirstCacheEntryInfoBufferSize = 0;
FindFirstUrlCacheEntryEx(null, 0, NORMAL_CACHE_ENTRY, 0, (IntPtr)null,
ref vFirstCacheEntryInfoBufferSize, null, null, null);
IntPtr vBuffer = Marshal.AllocHGlobal((int)vFirstCacheEntryInfoBufferSize);
vHandle = FindFirstUrlCacheEntryEx(null, 0, NORMAL_CACHE_ENTRY, 0,
vBuffer, ref vFirstCacheEntryInfoBufferSize,
null, null, null);
while (vHandle != null)
{
Marshal.PtrToStructure(vBuffer, vInternetCacheEntryInfo);
richTextBox1.AppendText(vInternetCacheEntryInfo.lpszSourceUrlName + "\r\n");
Marshal.FreeCoTaskMem(vBuffer);
FindNextUrlCacheEntryEx(vHandle, (IntPtr)null, ref vFirstCacheEntryInfoBufferSize,
null, null, null);
vBuffer = Marshal.AllocHGlobal((int)vFirstCacheEntryInfoBufferSize);
if (!FindNextUrlCacheEntryEx(vHandle, vBuffer,
ref vFirstCacheEntryInfoBufferSize, null, null, null)) break;
}
Marshal.FreeCoTaskMem(vBuffer);
}
//-------接口方式-------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace IEHistory
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IUrlHistoryStg2 vUrlHistoryStg2 = (IUrlHistoryStg2)new UrlHistory();
IEnumSTATURL vEnumSTATURL = vUrlHistoryStg2.EnumUrls();
STATURL vSTATURL;
uint vFectched;
while (vEnumSTATURL.Next(1, out vSTATURL, out vFectched) == 0)
{
richTextBox1.AppendText(string.Format("{0}:{1}\r\n",
vSTATURL.pwcsTitle, vSTATURL.pwcsUrl));
}
//vUrlHistoryStg2.ClearHistory();//清除历史
}
}
struct STATURL
{
public static uint SIZEOF_STATURL =
(uint)Marshal.SizeOf(typeof(STATURL));
public uint cbSize;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsUrl;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsTitle;
public FILETIME ftLastVisited,
ftLastUpdated,
ftExpires;
public uint dwFlags;
}
[ComImport, Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IEnumSTATURL
{
[PreserveSig]
uint Next(uint celt, out STATURL rgelt, out uint pceltFetched);
void Skip(uint celt);
void Reset();
void Clone(out IEnumSTATURL ppenum);
void SetFilter(
[MarshalAs(UnmanagedType.LPWStr)] string poszFilter,
uint dwFlags);
}
[ComImport, Guid("AFA0DC11-C313-11d0-831A-00C04FD5AE38"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IUrlHistoryStg2
{
#region IUrlHistoryStg methods
void AddUrl(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
[MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,
uint dwFlags);
void DeleteUrl(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
uint dwFlags);
void QueryUrl(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
uint dwFlags,
ref STATURL lpSTATURL);
void BindToObject(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
ref Guid riid,
[MarshalAs(UnmanagedType.IUnknown)] out object ppvOut);
IEnumSTATURL EnumUrls();
#endregion
void AddUrlAndNotify(
[MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
[MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,
uint dwFlags,
[MarshalAs(UnmanagedType.Bool)] bool fWriteHistory,
[MarshalAs(UnmanagedType.IUnknown)] object /*IOleCommandTarget*/
poctNotify,
[MarshalAs(UnmanagedType.IUnknown)] object punkISFolder);
void ClearHistory();
}
[ComImport, Guid("3C374A40-BAE4-11CF-BF7D-00AA006946EE")]
class UrlHistory /* : IUrlHistoryStg[2] */ { }
}