using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication34
{
class Program
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct internet_cache_entry_info
{
public int dwstructsize;
public IntPtr lpszsourceurlname;
public IntPtr lpszlocalfilename;
public int cacheentrytype;
public int dwusecount;
public int dwhitrate;
public int dwsizelow;
public int dwsizehigh;
public FILETIME lastmodifiedtime;
public FILETIME expiretime;
public FILETIME lastaccesstime;
public FILETIME lastsynctime;
public IntPtr lpheaderinfo;
public int dwheaderinfosize;
public IntPtr lpszfileextension;
public int dwexemptdelta;
}
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr FindFirstUrlCacheEntry([MarshalAs(UnmanagedType.LPTStr)] string urlsearchpattern, IntPtr lpfirstcacheentryinfo, ref int lpdwfirstcacheentryinfobuffersize);
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool GetUrlCacheEntryInfo([MarshalAs(UnmanagedType.LPTStr)] string lpszurlname, IntPtr lpcacheentryinfo, ref int lpdwcacheentryinfobuffersize);
public static string getcatchfilename(string url)
{
int nneeded = 0, nbufsize = 0;
IntPtr buf = IntPtr.Zero;
FindFirstUrlCacheEntry(null, IntPtr.Zero, ref nneeded);
nbufsize = nneeded; buf = Marshal.AllocHGlobal(nbufsize);
internet_cache_entry_info cacheitem;
GetUrlCacheEntryInfo(url, buf, ref nneeded);
cacheitem = (internet_cache_entry_info)Marshal.PtrToStructure(buf, typeof(internet_cache_entry_info));
string res = Marshal.PtrToStringAuto(cacheitem.lpszlocalfilename);
return (res);
}
static void Main(string[] args)
{
string str = getcatchfilename("http://profile.csdn.net/jinjazz/picture/2.jpg");
Console.WriteLine(str);
Console.Read();
}
}
}
Wininetdll函数库:根据url获取缓存文件
精选 转载rmlifejun 博主文章分类:MemberCached
下一篇: 一个通用快速的反射方法调用
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java 根据HttpEntity 中contenttype获取文件类型
java 根据HttpEntity 中contenttype获取文件类型
apache HTTP Apache -
java根据表名称获取所有字段
java根据表名称获取所有字段
字段 java sql -
Android 图片缓存函数库 Glide vs Picasso
方式,这两个库
android glide picasso ide 加载 -
函数库java 函数库和库函数
&n
函数库java 头文件 库函数 函数库 -
java根据url获取json对象 java根据url获取文件流
我们需要通过一个URL地址获取文件并转为blob流传给前端
java 开发语言 前端 下载文件 临时文件