Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7498749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:35:07+00:00 2026-05-29T19:35:07+00:00

I beg your pardon, if its a silly question. But I really need to

  • 0

I beg your pardon, if its a silly question. But I really need to know how can I use the code I am posting below. I have copied it from a form. I want to implement folder/file icon overlay. So while searching, I found the below code.

public sealed class ShellInterop
    {

        private ShellInterop()
        {
        }
        [DllImport("shell32.dll")]
        public static extern void SHChangeNotify(int eventID, uint flags, IntPtr item1, IntPtr item2);

    }

    [ComVisible(false)]
    [ComImport]
    [Guid("0C6C4200-C589-11D0-999A-00C04FD655E1")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IShellIconOverlayIdentifier
    {

        [PreserveSig]
        int IsMemberOf([MarshalAs(UnmanagedType.LPWStr)]string path, uint attributes);

        [PreserveSig]
        int GetOverlayInfo(
            IntPtr iconFileBuffer,
            int iconFileBufferSize,
            out int iconIndex,
            out uint flags);

        [PreserveSig]
        int GetPriority(out int priority);
    }

    [ComVisible(true)]
    [Guid("B8FA9E43-38E6-4654-8A13-FF905AD22CE5")]
    public class MyIconOverlay : IShellIconOverlayIdentifier
    {

        #region IShellIconOverlayIdentifier Members
        public int IsMemberOf(string path, uint attributes)
        {
            //Show everything with icon overlay
            return 0; // S_OK
        }

        public int GetOverlayInfo(IntPtr iconFileBuffer, int
        iconFileBufferSize,
        out int iconIndex, out uint flags)
        {

            System.Diagnostics.Debug.WriteLine(string.Format("GetOverlayInfo::{0}", iconFileBuffer));

            System.Diagnostics.Debug.WriteLine(string.Format("GetOverlayInfo::{0}", iconFileBufferSize));
            string fname = @"c:\NormalIcon.ico";

            int bytesCount = System.Text.Encoding.Unicode.GetByteCount(fname);

            System.Diagnostics.Debug.WriteLine(string.Format("GetOverlayInfo::{0}", bytesCount));

            byte[] bytes = System.Text.Encoding.Unicode.GetBytes(fname);

            if (bytes.Length + 2 < iconFileBufferSize)
            {
                for (int i = 0; i < bytes.Length; i++)
                {
                    Marshal.WriteByte(iconFileBuffer, i, bytes[i]);
                }
                //write the "\0\0"
                Marshal.WriteByte(iconFileBuffer, bytes.Length, 0);
                Marshal.WriteByte(iconFileBuffer, bytes.Length + 1, 0);
            }

            iconIndex = 0;
            flags = 1; // ISIOI_ICONFILE
            return 0; // S_OK
        }


        public int GetPriority(out int priority)
        {
            priority = 0; // 0-100 (0 is highest priority)
            return 0; // S_OK
        }
        #endregion

        #region Registry
        [ComRegisterFunction]
        public static void Register(Type t)
        {
            RegistryKey rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\_"
            + t.Name);
            rk.SetValue(string.Empty, t.GUID.ToString("B").ToUpper());
            rk.Close();
            ShellInterop.SHChangeNotify(0x08000000, 0, IntPtr.Zero, IntPtr.Zero);
        }

        [ComUnregisterFunction]
        public static void Unregister(Type t)
        {
            Registry.LocalMachine.DeleteSubKeyTree(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\_"
            + t.Name);
            ShellInterop.SHChangeNotify(0x08000000, 0, IntPtr.Zero, IntPtr.Zero);
        }
        #endregion
    }

Please if anyone can explain it to me. I have a situation, where I have to implement icon overlay for files and folder that a user creates under a special folder.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:35:09+00:00Added an answer on May 29, 2026 at 7:35 pm

    (edit: fixed regsvr32 to regasm, sorry for my mistake)

    This code has three main parts:
    1) An interop signature for the IShellIconOverlayIdentifier, the interface used by the shell to add icon overlays.
    2) MyOverlay, an implementation of that interface, adding (I’m guessing) the “normalIcon.ico” as the overlay.

    3) (this is the important part) code to register and unregister MyOverlay as a shell extension in the registry.

    I’m not too familiar with the specifics of icon overlays, but it seems that to enable this you need to call the Register method. Since it’s marked with a [ComRegisterFunction], I’m guessing all you have to do, from a command prompt with admin privileges, is call

    C:\> regasm <path to your DLL>
    

    which should call Register. Likewise with regasm /u <path> to uninstall. Give it a try.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hardly know any Jquery or Javascript. So, I beg your pardon in advance
I beg pardon for not doing homework on this issue and directly asking question
I have a small code block that should append text to the beg of
I'm doing some file io and created the test below, but I thought testoutput2.txt
I don't even know if this question belongs here or to another StackExchange site,
I know it's my fault and it is not complicated but I cannot find
How can I use a string as a method call? Some Word.class #=> String
The code below will print all of the text from the sample text file
I've faced a problem I can't solve that's why I beg you to help
I'm sure this question was answered thousands time before, but English is not my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.