Exemple #1
0
        internal static int GetPropertyValue(this IPropertySetStorage propertySetStorage, Guid fmtid, uint propid, out PROPVARIANT propvar)
        {
            HRESULT hr = (int)HRESULT.E_FAIL;

            propvar = default(PROPVARIANT);

            PROPSPEC[]       propspec        = new PROPSPEC[1];
            PROPVARIANT[]    propvars        = { propvar };
            IPropertyStorage propertyStorage = null;
            uint             grfMode         = (uint)(STGM.READ | STGM.SHARE_EXCLUSIVE);

            try
            {
                if (NativeMethods.Succeeded(hr = propertySetStorage.Open(ref fmtid, grfMode, out propertyStorage)))
                {
                    hr = propertyStorage.GetProperty(propid, out propvar);
                }
            }
            catch
            {
            }
            finally
            {
                if (propertyStorage != null)
                {
                    propertyStorage.FinalRelease();
                }
            }

            return(hr);
        }
Exemple #2
0
        internal static int GetPropertyName(this IPropertySetStorage propertySetStorage, Guid fmtid, uint propid, out string name)
        {
            HRESULT hr = (int)HRESULT.E_FAIL;

            name = String.Empty;

            IPropertyStorage propertyStorage = null;
            uint             grfMode         = (uint)(STGM.READ | STGM.SHARE_EXCLUSIVE);

            try
            {
                if (NativeMethods.Succeeded(hr = propertySetStorage.Open(ref fmtid, grfMode, out propertyStorage)))
                {
                    hr = propertyStorage.GetPropertyName(propid, out name);
                }
            }
            catch
            {
            }
            finally
            {
                if (propertyStorage != null)
                {
                    propertyStorage.FinalRelease();
                }
            }

            return(hr);
        }
Exemple #3
0
        private void LoadPropertySets()
        {
            HRESULT             hr         = (int)HRESULT.E_FAIL;
            IEnumSTATPROPSETSTG enumerator = null;

            STATPROPSETSTG[] stat    = new STATPROPSETSTG[1];
            uint             fetched = 0;
            List <Guid>      fmtids  = new List <Guid>();

            // Build list of FMTID's.
            try
            {
                if (NativeMethods.Succeeded(hr = _propertySetStorage.Enum(out enumerator)))
                {
                    while (NativeMethods.Succeeded(hr = (enumerator.Next(1, stat, out fetched))) && (fetched == 1))
                    {
                        fmtids.Add(stat[0].fmtid);
                    }

                    // IPropertySetStorage.Enum() does not enumerate FMTID_UserDefinedProperties.
                    // Note that FMTID_UserDefinedProperties may not exist.
                    fmtids.Add(FormatId.UserDefinedProperties);
                }

                foreach (Guid fmtid in fmtids)
                {
                    Guid rfmtid  = fmtid;
                    uint grfMode = (uint)(STGM.READ | STGM.SHARE_EXCLUSIVE);
                    //uint grfMode = (uint)(STGM.DIRECT | STGM.READ | STGM.SHARE_DENY_WRITE);
                    IPropertyStorage propertyStorage = null;

                    try
                    {
                        if (NativeMethods.Succeeded(hr = _propertySetStorage.Open(ref rfmtid, grfMode, out propertyStorage)))
                        {
                            _propertySets.Add(PropertySet.FromIPropertyStorage(propertyStorage));
                        }
                    }
                    catch
                    {
#if DEBUG
                        System.Diagnostics.Debugger.Break();
#endif
                    }
                    finally
                    {
                        if (propertyStorage != null)
                        {
                            propertyStorage.FinalRelease();
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (enumerator != null)
                {
                    enumerator.FinalRelease();
                }
            }
        }