.
In Depth Banner
Skip Navigation Links

Select your preferred language

Shell Extension stages.

Stage 1. The bare-bones DLL.

using System;

using System.Drawing;

using System.Runtime.InteropServices;

using ExtractImageInterop;

 

namespace WellFormed

{

  /// <summary>

  /// Summary description for ThumbExt.

  /// </summary>

  [ClassInterface(ClassInterfaceType.None),

  Guid("E134E0A2-5682-41d4-AF22-6F516844C094")]

  public class ThumbExt : IExtractImage, IPersistFile

  {

 

 

    public ThumbExt()

    {

      //

      // TODO: Add constructor logic here

      //

    }

 

    #region IExtractImage Members

 

    public void Extract(System.IntPtr phBmpThumbnail)

    {

    }

 

    public void GetLocation(string pszPathBuffer, uint cch, ref uint pdwPriority, ref tagSIZE prgSize, uint dwRecClrDepth, ref uint pdwFlags)

    {

    }

 

    #endregion

 

    #region IPersistFile Members

 

    public void SaveCompleted(string pszFileName)

    {

    }

 

    public void GetCurFile(out string ppszFileName)

    {

    }

 

    public void GetClassID(out Guid pClassID)

    {

    }

 

    public void Load(string pszFileName, uint dwMode)

    {

    }

 

    public void IsDirty()

    {

    }

 

    public void Save(string pszFileName, int fRemember)

    {

    }

 

    #endregion

  }

}

 

In stage 1 we have a project that imports the interop DLL, has a GUID, has the stubs of the interface implementations and has been configured by right clicking on the project, selecting Properties and enabling the option to "Register for COM interop" as seen in the following image.

 

Stage 2. The full implementation

using System;

using System.Drawing;

using System.Runtime.InteropServices;

using ExtractImageInterop;

 

namespace WellFormed

{

  /// <summary>

  /// Summary description for ThumbExt.

  /// </summary>

  [ClassInterface(ClassInterfaceType.None),

  Guid("E134E0A2-5682-41d4-AF22-6F516844C094")]

  public class ThumbExt : IExtractImage, IPersistFile

  {

 

    string filename;

    Size _size;

 

    public ThumbExt()

    {

      //

      // TODO: Add constructor logic here

      //

    }

    #region IExtractImage Members

 

    public void Extract(System.IntPtr phBmpThumbnail)

    {

      ColorShape cs=ColorShape.Load(filename);

      Bitmap bm=new Bitmap(_size.Width,_size.Height);

      Graphics g=Graphics.FromImage(bm);

      cs.Draw(g,new Rectangle(0,0,bm.Width,bm.Height));

      Marshal.WriteIntPtr(phBmpThumbnail,bm.GetHbitmap(Color.White));

      bm.Dispose();

    }

 

    public void GetLocation(string pszPathBuffer, uint cch, ref uint pdwPriority, ref tagSIZE prgSize, uint dwRecClrDepth, ref uint pdwFlags)

    {

      _size=new Size(prgSize.cx,prgSize.cy);

      pdwPriority=0x10000000u; //normal priority

    }

 

    #endregion

 

    #region IPersistFile Members

 

    public void SaveCompleted(string pszFileName)

    {

      throw new NotImplementedException();

    }

 

    public void GetCurFile(out string ppszFileName)

    {

      throw new NotImplementedException();

    }

 

    public void GetClassID(out Guid pClassID)

    {

      throw new NotImplementedException();

    }

 

    public void Load(string pszFileName, uint dwMode)

    {

      this.filename=pszFileName;

    }

 

    public void IsDirty()

    {

      throw new NotImplementedException();

    }

 

    public void Save(string pszFileName, int fRemember)

    {

      throw new NotImplementedException();

    }

 

    #endregion

  }

}

 

 

Use your Back button to return to the article

Copyright © Bob Powell 2000-.  All rights reserved.