根据验证码的URL得出在IE缓存中的图片路径
Uses WinINet;
//只对部份验证码会出现在缓存中有效,否则要利用取得验证码在WebBrowser所在的坐标捉取,或者可采用MSHTML对IMG标记复制出来
Function GetCacheVerifyCodeFile(VerifyCodeURL: String; Var CacheVerifyCodeFile: String): Boolean;
Var
lpEntryInfo: PInternetCacheEntryInfo;
dwEntrySize, dwLastError, Hwd: LongWORD;
i, j: Integer;
f: String;
Begin
Result := false;
dwEntrySize := 0;
j := 0;
CacheVerifyCodeFile := '';
FindFirstUrlCacheEntry(Nil, TInternetCacheEntryInfo(Nil^), dwEntrySize);
GetMem(lpEntryInfo, dwEntrySize);
Hwd := FindFirstUrlCacheEntry(Nil, lpEntryInfo^, dwEntrySize);
If Hwd <> 0 Then
Begin
Repeat
dwEntrySize := 0;
FindNextUrlCacheEntry(Hwd, TInternetCacheEntryInfo(Nil^), dwEntrySize);
dwLastError := GetLastError();
If dwLastError = ERROR_INSUFFICIENT_BUFFER Then
Begin
GetMem(lpEntryInfo, dwEntrySize);
If FindNextUrlCacheEntry(Hwd, lpEntryInfo^, dwEntrySize) Then
If Pos(UpperCase(VerifyCodeURL), UpperCase(lpEntryInfo.lpszSourceUrlName)) > 0 Then
Begin
i := FileAge(lpEntryInfo.lpszLocalFileName);
If i > j Then
Begin
j := i;
f := lpEntryInfo.lpszLocalFileName;
End;
End;
End;
Application.ProcessMessages;
Until (dwLastError = ERROR_NO_MORE_ITEMS);
If FileExists(f) Then
Begin
CacheVerifyCodeFile := f;
Result := true;
End;
End;
FreeMem(lpEntryInfo);
FindCloseUrlCache(Hwd);
End;