IPersistStream (Interfaces)
Last changed: -199.181.202.7

.

    /// <summary>
    /// Definition for interface IPersist.
    /// </summary>
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0000010c-0000-0000-C000-000000000046")]
    public interface IPersist {
        /// <summary>
        /// getClassID
        /// </summary>
        /// <param name="pClassID"></param>
        void GetClassID( /* [out] */ out Guid pClassID);
    };
    /// <summary>
    /// Definition for interface IPersistStream.
    /// </summary>
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000109-0000-0000-C000-000000000046")]
    public interface IPersistStream : IPersist {
        /// <summary>
        /// GetClassID
        /// </summary>
        /// <param name="pClassID"></param>
        new void GetClassID(out Guid pClassID);
        /// <summary>
        /// isDirty
        /// </summary>
        /// <returns></returns>
        [PreserveSig]
        int IsDirty( );
        /// <summary>
        /// Load
        /// </summary>
        /// <param name="pStm"></param>
        void Load([In] IStream pStm);
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="pStm"></param>
        /// <param name="fClearDirty"></param>
        void Save([In] IStream pStm, [In, MarshalAs(UnmanagedType.Bool)] bool fClearDirty);
        /// <summary>
        /// GetSizeMax
        /// </summary>
        /// <param name="pcbSize"></param>
        void GetSizeMax(out long pcbSize);
    };

     // Example -----------------------Note: In C#, use IPersistStreamInit ----------------------
    public  string    _strErrorMsg;

    public string GetComObjectGUID(object objComCtrl)
    {
        IntPtr pIPStream = IntPtr.Zero;
        string strStreamGUID = "NONE";
        IntPtr pActiveXObj = IntPtr.Zero;
        int iResult;
        int S_OK = 0;
        int E_FAIL = unchecked((int)0x80004005);
        int E_NOINTERFACE = unchecked((int)0x80004002);
        Guid IID_IPersistStreamInit = new Guid("7FD52380-4E07-101B-AE2D-08002B2EC713");

        if (Marshal.IsComObject((object)objComCtrl))
        {
              pActiveXObj = Marshal.GetIUnknownForObject((object)objComCtrl);
            if (pActiveXObj == IntPtr.Zero)
            {
                ErrorMsg = "GetIUnknownForObject was zero.";
            }
            else
            {
               iResult = Marshal.QueryInterface(pActiveXObj, ref IID_IPersistStreamInit, out pIPStream);
               if (iResult == E_NOINTERFACE)
               {
                    ErrorMsg = "No such interface supported";
               }            
               else if (iResult == E_FAIL)
               {
                    ErrorMsg = "PersistStreamInit QueryInit failed.";
               }
               else if (iResult == S_OK)
               {
                    IPersistStreamInit pPersistStream = (
                    IPersistStreamInit)Marshal.GetObjectForIUnknown(pIPStream);
                    Guid ptrClsId = new Guid();
                    pPersistStream.GetClassID(ref ptrClsId);
                    strStreamGUID = ptrClsId.ToString().ToUpper();
               }
            }
        }
        return (strStreamGUID);
    }

    public string ErrorMsg
     {
          get {return _strErrorMsg;}
          set {_strErrorMsg = value;}
     }