如何在我的C#项目中使用shell32.dll中的图像?

Max*_*r88 8 c# shell32.dll

如何在我的C#项目中使用shell32.dll中的图像?

Tho*_*que 14

您可以使用以下代码从DLL中提取图标:

public class IconExtractor
{

    public static Icon Extract(string file, int number, bool largeIcon)
    {
        IntPtr large;
        IntPtr small;
        ExtractIconEx(file, number, out large, out small, 1);
        try
        {
            return Icon.FromHandle(largeIcon ? large : small);
        }
        catch
        {
            return null;
        }

    }
    [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);

}

...

form.Icon = IconExtractor.Extract("shell32.dll", 42, true);
Run Code Online (Sandbox Code Playgroud)

当然你需要知道DLL中图像的索引...