zmiana ikony innej aplikacji

0

---Witam!
Napisałem klasę do modyfikowania zasobów programu:

class resource
{        
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern IntPtr BeginUpdateResource(string pFileName, [MarshalAs(UnmanagedType.Bool)]bool bDeleteExistingResources);
-
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool UpdateResource(IntPtr hUpdate, uint lpType, uint lpName, ushort wLanguage, byte[] lpData, uint cbData);

        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool EndUpdateResource(IntPtr hUpdate, bool fDiscard);

        public bool writeres(string path, uint name, uint type, byte[] data)
        {
            IntPtr h1 = BeginUpdateResource(Path.GetFullPath(path), false);
            UpdateResource(h1, type, name, 0, data, Convert.ToUInt32(data.Length));
            EndUpdateResource(h1, false);
            if (h1 == null)
                return false;
            else
                return true;
        }
}
 

i
public void seticon(string filename, System.Drawing.Image img)
{
resources res = new resources();
string tmpicon = "mojaikona.ico";
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
IntPtr hIcon = bmp.GetHicon();
System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(hIcon);
using (FileStream fs = new FileStream(tmpicon, FileMode.Create))
{
icon.Save(fs);
}
bmp.Dispose();
DestroyIcon(hIcon);
byte[] t = File.ReadAllBytes(tmpicon);
res.writeres(filename, 1, 3, t);
}
Ikona się nie zmieniła. Resedit wyświetla "Invalid resource format Type: 3, name: 1". Co jest w tym kodzie błędnie napisane? Jak zrobić żeby Resedit nie wyświetlał błędu?

0

Chodzi mi o ikonę w Eksploratorze Windows.

1 użytkowników online, w tym zalogowanych: 0, gości: 1