Skip to content

Instantly share code, notes, and snippets.

@CoenraadS
Created July 16, 2014 16:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoenraadS/86e80d8e7279b64b7989 to your computer and use it in GitHub Desktop.
Save CoenraadS/86e80d8e7279b64b7989 to your computer and use it in GitHub Desktop.
ExtractIconExW Issue
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Drawing;
using Microsoft.Win32;
namespace ConsoleApplication1
{
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);
Console.WriteLine("Large: " + largeIconPtr.ToString());
Console.WriteLine("Small: " + smallIconPtr.ToString());
Console.WriteLine();
//HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{40419485-C444-4567-851A-2DD7BFA1684D}\DefaultIcon
Console.WriteLine("telephon.cpl");
Console.WriteLine("Icon Index = 100");
ExtractIconEx(@"%SystemRoot%\System32\telephon.cpl", 100, out largeIconPtr, out smallIconPtr, 1);
Console.WriteLine("Large: " + largeIconPtr.ToString());
Console.WriteLine("Small: " + smallIconPtr.ToString());
Console.WriteLine();
Console.WriteLine("Icon Index = -100");
ExtractIconEx(@"%SystemRoot%\System32\telephon.cpl", -100, out largeIconPtr, out smallIconPtr, 1);
Console.WriteLine("Large: " + largeIconPtr.ToString());
Console.WriteLine("Small: " + smallIconPtr.ToString());
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment