示例#1
0
        public object GetValue(PROPERTYKEY key)
        {
            var    pv    = IntPtr.Zero;
            object value = null;

            try {
                pv = Marshal.AllocCoTaskMem(16);
                m_IPropertyStore.GetValue(key, pv);
                try {
                    value = PropVariant.ToObject(pv);
                }
                catch (Exception err) {
                    throw new ApplicationException("Unsupported property data type", err);
                }
            }
            finally {
                if (pv != (IntPtr)0)
                {
                    try {
                        NativeMethods.PropVariantClear(pv);
                    }
                    catch {
                        Debug.Fail("VariantClear failure");
                    }

                    Marshal.FreeCoTaskMem(pv);
                    pv = IntPtr.Zero;
                }
            }

            return(value);
        }
        public PropertyDescription GetPropertyDescription(PROPERTYKEY propKey)
        {
            var IID_IPropertyDescription = typeof(NativeMethods.IPropertyDescription).GUID;

            NativeMethods.IPropertyDescription iPropertyDescription;
            m_IPropertySystem.GetPropertyDescription(propKey, ref IID_IPropertyDescription, out iPropertyDescription);
            return(new PropertyDescription(iPropertyDescription));
        }
示例#3
0
        public void SetValue(PROPERTYKEY key, object value)
        {
            var pv = IntPtr.Zero;

            try {
                pv = NativeMethods.PropVariantFromObject(value);
                m_IPropertyStore.SetValue(key, pv);
            }
            finally {
                if (pv != IntPtr.Zero)
                {
                    NativeMethods.PropVariantClear(pv);
                    Marshal.FreeCoTaskMem(pv);
                    pv = IntPtr.Zero;
                }
            }
        }