Click here to Skip to main content
15,886,258 members
Articles / Desktop Programming / Win32

.NET Shell Extensions - Shell Context Menus

Rate me:
Please Sign up or sign in to vote.
4.93/5 (132 votes)
29 Jun 2019CPOL9 min read 840.4K   22.3K   403  
Rapidly create Shell Context Menu Extensions using .NET
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG;

namespace SharpShell
{
    public class ShellStream : Stream
    {

        public ShellStream(IStream shellStream)
        {
            this.shellStream = shellStream;
        }

        public override bool CanRead
        {
            get { return true; }
        }

        public override bool CanSeek
        {
            get { return true; }
        }

        public override bool CanWrite
        {
            get { return true; }
        }

        public override void Flush()
        {
            shellStream.Commit(0);
        }

        public override long Length
        {
            get
            {
                ulong size;
                IStream_Size(shellStream, out size);
                return (long) size;
            }
        }

        public override long Position
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            throw new NotImplementedException();
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotImplementedException();
        }

        public override void SetLength(long value)
        {
            throw new NotImplementedException();
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            throw new NotImplementedException();
        }

        [DllImport("Shlwapi.dll")]
        [PreserveSig]
        private static extern int IStream_Size(IStream pstm, out UInt64 pui);

        private readonly IStream shellStream;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.

Comments and Discussions