Ejemplo n.º 1
0
 /// <summary>
 /// Creates a <see cref="PropertyKey"/> with the specified <see cref="FmtId"/> and <see cref="Pid"/>
 /// </summary>
 /// <param name="fmtid">The <see cref="Guid"/> that identifies this PropertyKey</param>
 /// <param name="pid">The numerical pid that identifies this PropertyKey</param>
 public PropertyKey(Guid fmtid, uint pid)
 {
     _propKey = new PROPERTYKEY()
     {
         fmtid = fmtid, pid = pid
     };
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="PropertyKey"/>  from either a canonical name or a formatted PropertyKey.
        /// </summary>
        /// <param name="formatString">This string may either be the canonical name of a PropertyKey, or a formatted PropertyKey string.
        /// The former of these formats contain two or more user friendly names, delimited by a period(.) e.g. "System.Title", "System.Image.Dimensions". The other format is a string consisting of the
        /// PropertyKey's <see cref="FmtId"/>, which is a <see cref="Guid"/>, and the <see cref="Pid"/>, which is an integral value. The string will be formatted as "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} nn",
        /// where the {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} is the formatted Guid, and the nn is the Pid.
        /// </param>
        public PropertyKey(string formatString)
        {
            HRESULT hr;

            _ppk = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(PROPERTYKEY)));
            try {
                // Is it a formatted propertykey or a canonical name?
                if (formatString.StartsWith("{"))
                {
                    hr = PSPropertyKeyFromString(formatString, _ppk);
                    if (hr.Failed)
                    {
                        throw hr.GetException();
                    }
                }
                else
                {
                    hr = PSGetPropertyKeyFromName(formatString, _ppk);
                    if (hr.Failed)
                    {
                        throw hr.GetException();
                    }
                }
            }
            catch {
                Marshal.FreeCoTaskMem(_ppk);
                _ppk = IntPtr.Zero;
                throw;
            }
            _propKey = Marshal.PtrToStructure <PROPERTYKEY>(_ppk);
        }
Ejemplo n.º 3
0
 internal PropertyKey(IntPtr ppk)
 {
     _ppk     = ppk;
     _propKey = Marshal.PtrToStructure <PROPERTYKEY>(_ppk);
 }
Ejemplo n.º 4
0
 internal PropertyKey()
 {
     _propKey = new PROPERTYKEY();
 }
Ejemplo n.º 5
0
 internal PropertyKey(PROPERTYKEY propKey)
 {
     _propKey = propKey;
 }