我想通过 dll 处理文件扩展名图标并根据 Windows 资源管理器中的文件内容提供图标(类似于 PSD 文件的缩略图图标。Photoshop 处理 .psd 扩展名并为每个文件生成缩略图)
Load
我用 C# 制作了一个可以很好地处理和运行的 dll GetIconLocation
。似乎 Windows 应该在之后调用该Extract
函数,GetIconLocation
但它不会!
界面:
[ComVisible(true), ComImport, Guid("000214eb-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IExtractIcon
{
[PreserveSig]
uint GetIconLocation(int uFlags, IntPtr szIconFile, int cchMax, IntPtr piIndex, UIntPtr pwFlags);
//[PreserveSig]
//uint GetIconLocation(uint uFlags, IntPtr szIconFile, uint cchMax, IntPtr piIndex, UIntPtr pwFlags);
[PreserveSig]
uint Extract(string pszFile, uint nIconIndex, ref IntPtr phiconLarge,ref IntPtr phiconSmall, uint nIconSize);
}
和功能:
public uint Load(string pszFileName, uint dwMode)//Using IPersistFile
{
icon_File = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Icon.bmp");
tip = "My tool-tip";
Logger.WriteLog("Load :"+pszFileName+" , "+dwMode.ToString());
return S_OK;
}
public uint GetIconLocation(int uFlags, IntPtr szIconFile, int cchMax, IntPtr piIndex, UIntPtr pwFlags)//Using IExtractIcon and IPersistFile.Load
{
try
{
IconHandlerReturnFlags Flags;
Flags = IconHandlerReturnFlags.PerClass | IconHandlerReturnFlags.DontCache | IconHandlerReturnFlags.NotFilename;
pwFlags = (UIntPtr)Flags;
Logger.WriteLog("GetIconLocation...");
return S_OK;
}
catch (Exception e)
{
Logger.WriteLog("GetIconLocation " + e.Message);
return S_FALSE;
}
}
public uint Extract(string pszFile, uint nIconIndex, ref IntPtr phiconLarge,ref IntPtr phiconSmall, uint nIconSize)//Using IExtractIcon
{
Logger.WriteLog("Extract...");
// other code...
}
Load
功能正常工作并提供正确的文件名。也GetIconLocation
有效。但是在返回 S_OK 值后提取不会执行...:(
这是.myf
在 Windows 资源管理器中查看两个文件图标后的日志
Load : C:\**********1.Myf , 0
GetIconLocation...
Load : C:\**********2.Myf , 0
GetIconLocation...
Load : C:\**********1.Myf , 0
GetIconLocation...
GetIconLocation...
Load : C:\**********1.Myf , 0
GetIconLocation..
(有时两个GetIconLocation
电话没有Load
)
请有人帮助我....