// TestGetUrlCacheEntryInfo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <wininet.h>
#include <string>
#include <iostream>
using namespace std;
/*
功能:根据图片在IE中的URL得到图片文件在本地磁盘中的Path
测试时间:2013-07-15
测试环境:
[1]VS2008+SP1
[2]WinXP+IE8
依赖库:Wininet.lib
参考资料
[1]《C#读取IE的Cache》
http://www.cnblogs.com/lxinxuan/archive/2006/10/26/540364.html
[2]《GetUrlCacheEntryInfo使用说明》
http://msdn.microsoft.com/zh-cn/subscriptions/aa384185(v=vs.85).aspx
*/
BOOL GetPathByURL(std::wstring url,std::wstring &path)
{
DWORD dwEntrySize=0;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry;
//假设lpszUrl是图片的url
if (!GetUrlCacheEntryInfo(url.c_str(),NULL,&dwEntrySize))
{
if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER)
{
return FALSE;
}
else
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO)new char[dwEntrySize];
}
else
return FALSE;
if (!GetUrlCacheEntryInfo(url.c_str(),lpCacheEntry,&dwEntrySize))
{
return FALSE;
}
else
{
path = lpCacheEntry->lpszLocalFileName;
return TRUE;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
if(argc!=2)
{
wcout<<"入口参数非法"<<endl;
wcout<<"Usage: <图片在IE中的URL地址>"<<endl;
return -1;
}
std::wstring url = argv[1];
std::wstring path;
if(TRUE==GetPathByURL(url,path))
{
wcout<<"path="<<path.c_str()<<endl;
} else
{
wcout<<"取path失败!"<<endl;
}
return 0;
}
根据图片在IE中的URL得到图片文件在本地磁盘中的Path
最新推荐文章于 2021-02-15 12:08:18 发布