我试图以编程方式从注册表中提取一些图标.但是我注意到不一致的行为.我在这里做了一个基本测试:
https://gist.github.com/CoenraadS/86e80d8e7279b64b7989
class Program
{
[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);
static void Main(string[] args)
{
IntPtr largeIconPtr = IntPtr.Zero;
IntPtr smallIconPtr = IntPtr.Zero;
//HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{1206F5F1-0569-412C-8FEC-3204630DFB70}\DefaultIcon
Console.WriteLine("Vault.dll");
ExtractIconEx(@"%SystemRoot%\system32\Vault.dll", 1, out largeIconPtr, out smallIconPtr, 1);
Console.WriteLine("Icon Index = 1");
Console.WriteLine("Large: " + largeIconPtr.ToString());
Console.WriteLine("Small: " + smallIconPtr.ToString());
Console.WriteLine();
Console.WriteLine("Icon Index = -1");
ExtractIconEx(@"%SystemRoot%\system32\Vault.dll", -1, out largeIconPtr, out smallIconPtr, 1); …Run Code Online (Sandbox Code Playgroud) c# ×1