using System; using System.Drawing; using System.IO; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; namespace PhotoThumbnail.Definitions { internal static class HandlerNativeMethods { internal static readonly Guid IThumbnailProviderGuid = new Guid("e357fccd-a995-4576-b01f-234630154e96"); //internal static readonly Guid IInitializeWithFileGuid = new Guid("b7d14566-0509-4cce-a71f-0a554233bd9b"); internal static readonly Guid IInitializeWithStreamGuid = new Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f"); //internal static readonly Guid IInitializeWithItemGuid = new Guid("7f73be3f-fb79-493c-a6c7-7ee14e245841"); internal static readonly Guid IMarshalGuid = new Guid("00000003-0000-0000-C000-000000000046"); } /// /// This interface exposes the function for initializing the /// Thumbnail Provider with a . /// If this interfaces is not used, then the handler must opt out of process isolation. /// This interface can be used in conjunction with the other intialization interfaces, /// but only 1 will be accessed according to the priorities preset by the Windows Shell: /// /// /// /// public interface IThumbnailFromStream { /// /// Provides the to the item from which a thumbnail should be created. /// Only 32bpp bitmaps support adornments. /// While 24bpp bitmaps will be displayed they will not display adornments. /// Additional guidelines for developing thumbnails can be found at http://msdn.microsoft.com/en-us/library/cc144115(v=VS.85).aspx /// /// /// Stream to initialize the thumbnail /// Square side dimension in which the thumbnail should fit; the thumbnail will be scaled otherwise. /// Bitmap ConstructBitmap(Stream stream, int sideSize); } /// /// The STGM constants are flags that indicate /// conditions for creating and deleting the object and access modes /// for the object. /// /// You can combine these flags, but you can only choose one flag /// from each group of related flags. Typically one flag from each /// of the access and sharing groups must be specified for all /// functions and methods which use these constants. /// [Flags] public enum AccessModes { /// /// Indicates that, in direct mode, each change to a storage /// or stream element is written as it occurs. /// Direct = 0x00000000, /// /// Indicates that, in transacted mode, changes are buffered /// and written only if an explicit commit operation is called. /// Transacted = 0x00010000, /// /// Provides a faster implementation of a compound file /// in a limited, but frequently used, case. /// Simple = 0x08000000, /// /// Indicates that the object is read-only, /// meaning that modifications cannot be made. /// Read = 0x00000000, /// /// Enables you to save changes to the object, /// but does not permit access to its data. /// Write = 0x00000001, /// /// Enables access and modification of object data. /// ReadWrite = 0x00000002, /// /// Specifies that subsequent openings of the object are /// not denied read or write access. /// ShareDenyNone = 0x00000040, /// /// Prevents others from subsequently opening the object in Read mode. /// ShareDenyRead = 0x00000030, /// /// Prevents others from subsequently opening the object /// for Write or ReadWrite access. /// ShareDenyWrite = 0x00000020, /// /// Prevents others from subsequently opening the object in any mode. /// ShareExclusive = 0x00000010, /// /// Opens the storage object with exclusive access to the most /// recently committed version. /// Priority = 0x00040000, /// /// Indicates that the underlying file is to be automatically destroyed when the root /// storage object is released. This feature is most useful for creating temporary files. /// DeleteOnRelease = 0x04000000, /// /// Indicates that, in transacted mode, a temporary scratch file is usually used /// to save modifications until the Commit method is called. /// Specifying NoScratch permits the unused portion of the original file /// to be used as work space instead of creating a new file for that purpose. /// NoScratch = 0x00100000, /// /// Indicates that an existing storage object /// or stream should be removed before the new object replaces it. /// Create = 0x00001000, /// /// Creates the new object while preserving existing data in a stream named "Contents". /// Convert = 0x00020000, /// /// Causes the create operation to fail if an existing object with the specified name exists. /// FailIfThere = 0x00000000, /// /// This flag is used when opening a storage object with Transacted /// and without ShareExclusive or ShareDenyWrite. /// In this case, specifying NoSnapshot prevents the system-provided /// implementation from creating a snapshot copy of the file. /// Instead, changes to the file are written to the end of the file. /// NoSnapshot = 0x00200000, /// /// Supports direct mode for single-writer, multireader file operations. /// DirectSingleWriterMultipleReader = 0x00400000 } // /// Thumbnail Alpha Types /// public enum ThumbnailAlphaType { /// /// Let the system decide. /// Unknown = 0, /// /// No transparency /// NoAlphaChannel = 1, /// /// Has transparency /// HasAlphaChannel = 2, } /// /// ComVisible interface for native IThumbnailProvider /// [ComImport] [Guid("e357fccd-a995-4576-b01f-234630154e96")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IThumbnailProvider { /// /// Gets a pointer to a bitmap to display as a thumbnail /// /// /// /// void GetThumbnail(uint squareLength, [Out] out IntPtr bitmapHandle, [Out] out uint bitmapType); } /// /// Provides means by which to initialize with a stream. /// [ComImport] [Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IInitializeWithStream { /// /// Initializes with a stream. /// /// /// void Initialize(IStream stream, AccessModes fileMode); } }