问题补充:
private string FILETIMEtoDataTime(FILETIME time)
{
IntPtr filetime = Marshal.AllocHGlobal( Marshal.SizeOf(typeof(FILETIME)) );
IntPtr systime = Marshal.AllocHGlobal( Marshal.SizeOf(typeof(SYSTEMTIME)) );
Marshal.StructureToPtr(time,filetime,true);
FileTimeToSystemTime( filetime ,systime);
SYSTEMTIME st = (SYSTEMTIME) Marshal.PtrToStructure(systime,typeof(SYSTEMTIME));
string Time = st.wYear.ToString()+"."+st.wMonth.ToString()+"."+st.wDay.ToString()+"."+st.wHour.ToString()+"."+st.wMinute.ToString()+"."+st.wSecond.ToString();
return Time;
}
#endregion
#region 加载数据
private void FileOk_Click(object sender, System.EventArgs e)
{
int nNeeded = 0, nBufSize;
IntPtr buf;
INTERNET_CACHE_ENTRY_INFO CacheItem;
IntPtr hEnum;
bool r;
FindFirstUrlCacheEntry( null, IntPtr.Zero, ref nNeeded );
if ( Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS )
return;
nBufSize = nNeeded;
buf = Marshal.AllocHGlobal( nBufSize );
hEnum = FindFirstUrlCacheEntry( null, buf, ref nNeeded );
while ( true )
{
CacheItem = (INTERNET_CACHE_ENTRY_INFO) Marshal.PtrToStructure( buf,
typeof(INTERNET_CACHE_ENTRY_INFO) );
string modifiedTime = FILETIMEtoDataTime(CacheItem.LastModifiedTime);
string expireTime = FILETIMEtoDataTime(CacheItem.ExpireTime);
string accessTime = FILETIMEtoDataTime(CacheItem.LastAccessTime);
string syncTime = FILETIMEtoDataTime(CacheItem.LastSyncTime);
#region 获得数据,存入数据库
try
{
//此处遍历CacheItem即可
//例如
string s = Marshal.PtrToStringAuto(CacheItem.lpszSourceUrlName);
}
string s = Marshal.PtrToStringAuto(CacheItem.lpszSourceUrlName);
nNeeded = nBufSize;
r = FindNextUrlCacheEntry( hEnum, buf, ref nNeeded );
if ( !r && Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS )
break;
if ( !r && nNeeded > nBufSize )
{
nBufSize = nNeeded;
buf = Marshal.ReAllocHGlobal( buf, (IntPtr) nBufSize );
FindNextUrlCacheEntry( hEnum, buf, ref nNeeded );
}
}
MessageBox.Show("系统数据加载完毕!");
Marshal.FreeHGlobal( buf );
}
#endregion