/// <summary> /// Called to clear the PropVariant's referenced and local memory. /// </summary> /// <remarks> /// You must call Clear to avoid memory leaks. /// </remarks> public void Clear() { // Can't pass "this" by ref, so make a copy to call PropVariantClear with PROPVARIANT var = this; NativeMethods.PropVariantClear(ref var); // Since we couldn't pass "this" by ref, we need to clear the member fields manually // NOTE: PropVariantClear already freed heap data for us, so we are just setting // our references to null. vt = (ushort)VarEnum.VT_EMPTY; wReserved1 = wReserved2 = wReserved3 = 0; p = IntPtr.Zero; p2 = 0; }
internal static PropertySet FromIPropertyStorage(IPropertyStorage propertyStorage) { if (propertyStorage == null) { throw new ArgumentNullException("propertyStorage"); } HRESULT hr = HRESULT.E_FAIL; PropertySet propertySet = null; STATPROPSETSTG stat; propertyStorage.Stat(out stat); IEnumSTATPROPSTG enumerator = null; List <Property> properties = new List <Property>(); try { if (NativeMethods.Succeeded(hr = propertyStorage.Enum(out enumerator))) { STATPROPSTG[] sps = new STATPROPSTG[] { default(STATPROPSTG) }; uint fetched = 0; while ((enumerator.Next(1, sps, out fetched) == HRESULT.S_OK) && (fetched == 1)) { string name; PROPVARIANT propvar = default(PROPVARIANT); try { propertyStorage.GetPropertyName(sps[0].propid, out name); sps[0].lpwstrName = name; propertyStorage.GetProperty(sps[0].propid, out propvar); properties.Add(new Property(sps[0], propvar.Value)); } catch { } finally { propvar.Clear(); } } } } catch { } finally { if (enumerator != null) { enumerator.FinalRelease(); } } Type type = System.Reflection.Assembly.GetExecutingAssembly().GetPropertySetType(stat.fmtid); if (type == null) { // In this case, we did not find a strongly typed property set. type = typeof(PropertySet); } propertySet = PropertySet.InvokeInternalConstructor(type, stat, properties.ToArray()); propertySet.Name = type.GetPropertySetName(); return(propertySet); }
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); }
internal static int GetPropertyValue(this IPropertySetStorage propertySetStorage, PIDDSI propid, out PROPVARIANT propvar) { return(propertySetStorage.GetPropertyValue(FormatId.DocSummaryInformation, (uint)propid, out propvar)); }
internal static int GetProperty(this IPropertyStorage propertyStorage, uint propid, out PROPVARIANT propvar) { HRESULT hr = (int)HRESULT.E_FAIL; propvar = default(PROPVARIANT); PROPSPEC[] propspec = new PROPSPEC[1]; PROPVARIANT[] propvars = { propvar }; propspec[0].ulKind = (uint)PRSPEC.PROPID; propspec[0].u.propId = propid; if (NativeMethods.Succeeded(hr = propertyStorage.ReadMultiple(1, propspec, propvars))) { propvar = propvars[0]; } return(hr); }
public extern static int PropVariantClear(ref PROPVARIANT pvar);
internal int GetPropertyValue(Guid fmtid, uint propid, out PROPVARIANT propvar) { IPropertySetStorage propertySetStorage = (IPropertySetStorage)_rootStorage; return(propertySetStorage.GetPropertyValue(fmtid, propid, out propvar)); }