翻譯自 http://blog.csdn.net/CathyEagle/archive/2004/11/05/167900.aspx
Private Declare Function GetUrlCacheEntryInfo Lib "wininet.dll" Alias _<br /> "GetUrlCacheEntryInfoW" (ByVal lpszUrlName As Long, ByVal lpCacheEntryInfo As _<br /> Long, ByRef lpdwCacheEntryInfoBufferSize As Long) As Long</p><p>Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122</p><p>Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)<br />Private Declare Function SysAllocString Lib "oleaut32.dll" (ByVal pOlechar As Long) As String</p><p>Private Type FILETIME<br /> dwLowDateTime As Long<br /> dwHighDateTime As Long<br />End Type</p><p>Private Type INTERNET_CACHE_ENTRY_INFO<br /> dwStructSize As Long<br /> lpszSourceUrlName As Long<br /> lpszLocalFileName As Long<br /> CacheEntryType As Long<br /> dwUseCount As Long<br /> dwHitRate As Long<br /> dwSizeLow As Long<br /> dwSizeHigh As Long<br /> LastModifiedTime As FILETIME<br /> ExpireTime As FILETIME<br /> LastAccessTime As FILETIME<br /> LastSyncTime As FILETIME<br /> lpHeaderInfo As Long<br /> dwHeaderInfoSize As Long<br /> lpszFileExtension As Long<br /> 'union {<br /> ' DWORD dwReserved;<br /> ' DWORD dwExemptDelta;<br /> '}<br /> dwReserved As Long<br />End Type</p><p>Private Function GetPathFromUrl(lpszUrl$) As String</p><p>Dim dwEntrySize&</p><p>Dim lpCacheEntry As INTERNET_CACHE_ENTRY_INFO</p><p>Dim lpCacheEntryByte() As Byte</p><p>Dim strTemp(80) As Byte<br />Dim dwTemp&</p><p>'假設lpszUrl是圖片的url<br />Call GetUrlCacheEntryInfo(StrPtr(lpszUrl), 0, dwEntrySize)</p><p>If Err.LastDllError = ERROR_INSUFFICIENT_BUFFER Then<br /> ReDim lpCacheEntryByte(dwEntrySize)<br /> Debug.Print dwEntrySize<br /> 'lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO)new char[dwEntrySize];<br />Else<br /> Exit Function<br />End If</p><p>Err.Clear</p><p>Call GetUrlCacheEntryInfo(StrPtr(lpszUrl), VarPtr(lpCacheEntryByte(0)), dwEntrySize)<br />Debug.Print Err.LastDllError<br />'If Err.LastDllError = 0 Then<br /> '//lpCacheEntry->lpszLocalFileName即是lpszUrl在緩衝中的檔案名稱<br /> 'return TRUE;</p><p> CopyMemory VarPtr(lpCacheEntry), VarPtr(lpCacheEntryByte(0)), Len(lpCacheEntry)</p><p> GetPathFromUrl = StrConv(SysAllocString(lpCacheEntry.lpszLocalFileName), vbFromUnicode)<br />'End If</p><p>End Function