using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; namespace Vanara.PInvoke { /// Exposes a method for manually copying a stream or file before applying changes to properties. /// /// The default copy-on-write behavior provided by IPropertyStore causes the entire source stream to be duplicated during a write /// operation. This can be costly for large streams, especially when a large portion of the stream is to be changed. /// IDestinationStreamFactory provides an alternative for the property handler author, who can use it manually to ensure that /// property changes do not corrupt the stream in case of failure. To do this, the author marks the handler as NoTransactedMode in the /// handler's CoClass registry key, and queries the stream for this interface. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-idestinationstreamfactory [PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IDestinationStreamFactory")] [ComImport, Guid("8a87781b-39a7-4a1f-aab3-a39b9c34a7d9"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IDestinationStreamFactory { /// Gets an empty stream that receives the new version of the file being copied. /// /// Type: IStream** /// The address of a pointer to the new stream. /// /// /// Type: HRESULT /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// The property handler author calls IDestinationStreamFactory::GetDestinationStream to get a new empty stream that the new /// version of the file will write to. The handler builds the destination stream manually, copying from the source stream as necessary. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-idestinationstreamfactory-getdestinationstream // HRESULT GetDestinationStream( IStream **ppstm ); [PreserveSig] HRESULT GetDestinationStream(out IStream ppstm); } }