gpt4 book ai didi

c# - 无法关闭 SHGetFileInfo

转载 作者:行者123 更新时间:2023-11-30 19:30:24 26 4
gpt4 key购买 nike

我有一个很好的技术来获取当前系统中的关联扩展/图像(因为扩展可以从一个系统到另一个系统有不同的图像)。这是函数:

public static Icon getIconFromFile(string ext, bool large = true)
{
string fileName = (new Random()).Next(100, 1000).ToString() + ext;
System.IO.File.Create(fileName);
System.Drawing.Icon icon;
SHFILEINFO shinfo = new SHFILEINFO();

if (large)
{
IntPtr hImgLarge = Win32.SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
}
else
{
IntPtr hImgSmall = Win32.SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);
icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
}
try
{
System.IO.File.Delete(fileName);
}
catch(Exception e)
{
System.Console.WriteLine(e.StackTrace);
}
return icon;
}

问题是函数没有关闭对文件的访问,所以我不能删除它。我能怎么做 ?谢谢

最佳答案

您不需要创建虚拟文件。 Use SHGFI_USEFILEATTRIBUTES .

关于c# - 无法关闭 SHGetFileInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9136259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com