如何從URL取得其在Internet Cache中的檔案名稱

來源:互聯網
上載者:User

翻譯自 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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.