Beispiel #1
0
        public PROPERTYKEY Get(int index)
        {
            PROPERTYKEY key;

            Marshal.ThrowExceptionForHR(_Store.GetAt(index, out key));
            return(key);
        }
Beispiel #2
0
        private PropertyKey Get(int index)
        {
            PropertyKey key;

            Marshal.ThrowExceptionForHR(_Store.GetAt(index, out key));
            return(key);
        }
        /// <summary>
        /// Gets property key at sepecified index
        /// </summary>
        /// <param name="index">Index</param>
        /// <returns>Property key</returns>
        public PropertyKey Get(int index)
        {
            PropertyKey key;

            Marshal.ThrowExceptionForHR(_underlyingStore.GetAt(index, out key));
            return(key);
        }
Beispiel #4
0
        /// <summary>
        /// Gets property key at specified index
        /// </summary>
        /// <param name="index">Index</param>
        /// <returns>Property key</returns>
        public PropertyKey Get(int index)
        {
            PropertyKey key;

            Marshal.ThrowExceptionForHR(storeInterface.GetAt(index, out key));
            return(key);
        }
Beispiel #5
0
 /// <summary>
 /// Gets the <see cref="PropertyStore"/> in this <see cref="PropertyStore"/> at the specified <paramref name="index"/>
 /// </summary>
 /// <param name="index">The zero-based index of the required property</param>
 /// <returns>The PropertyKey identifying the property at the specified <paramref name="index"/> </returns>
 public PropertyKey this[int index] {
     get {
         IntPtr ppk = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(PROPERTYKEY)));
         _pStore.GetAt((uint)index, ppk);
         return(new PropertyKey(ppk));
     }
 }
        private PropertyKey GetAt(uint index)
        {
            PropertyKey result;

            Marshal.ThrowExceptionForHR(_property.GetAt(index, out result));
            return(result);
        }
Beispiel #7
0
        private void AddProperties(IPropertyStore nativePropertyStore)
        {
            // Populate the property collection
            _ = nativePropertyStore.GetCount(out uint propertyCount);
            for (uint i = 0; i < propertyCount; i++)
            {
                _ = nativePropertyStore.GetAt(i, out PropertyKey propKey);

                Items.Add(ParentShellObject != null ? ParentShellObject.Properties.CreateTypedProperty(propKey) : CreateTypedProperty(propKey, NativePropertyStore));
            }
        }
Beispiel #8
0
        public PropertyKey GetAt(int index)
        {
            if ((index < 0) || (index >= Count))
            {
                throw new IndexOutOfRangeException(
                          String.Format("Index must be between 0 and {0} (inclusive) for this instance.", Count - 1));
            }

            PropertyKey result;

            HResult.Try(_propertyStoreInterface.GetAt((uint)index, out result));
            return(result);
        }
Beispiel #9
0
        /// <summary>Clones a property store to a memory property store.</summary>
        /// <param name="ps">The property store to clone.</param>
        /// <returns>The cloned memory property store.</returns>
        /// <exception cref="System.ArgumentNullException">ps</exception>
        public static MemoryPropertyStore ClonePropertyStoreToMemory(IPropertyStore ps)
        {
            if (ps is null)
            {
                throw new ArgumentNullException(nameof(ps));
            }
            var ms  = new MemoryPropertyStore();
            var cnt = ps.GetCount();

            for (var i = 0U; i < cnt; i++)
            {
                var key = ps.GetAt(i);
                ms.Add(key, ps.GetValue(key));
            }
            return(ms);
        }
        private Dictionary <PropertyKey, object> GetProperties(IMMDevice device)
        {
            var properties = new Dictionary <PropertyKey, object>();

            //Opening in write mode, can cause exceptions to be thrown when not run as admin.
            //This tries to open in write mode if available
            try
            {
                Marshal.ThrowExceptionForHR(device.OpenPropertyStore(StorageAccessMode.ReadWrite, out _propertyStoreInteface));
                Mode = AccessMode.ReadWrite;
            }
            catch
            {
                Debug.WriteLine("Cannot open property store in write mode");
            }

            if (_propertyStoreInteface == null)
            {
                Marshal.ThrowExceptionForHR(device.OpenPropertyStore(StorageAccessMode.Read, out _propertyStoreInteface));
                Mode = AccessMode.Read;
            }
            try
            {
                uint count;
                _propertyStoreInteface.GetCount(out count);
                for (uint i = 0; i < count; i++)
                {
                    PropertyKey key;
                    PropVariant variant;
                    _propertyStoreInteface.GetAt(i, out key);

                    _propertyStoreInteface.GetValue(ref key, out variant);

                    if (variant.IsSupported())
                    {
                        properties.Add(key, variant.Value);
                    }
                }
            }
            catch
            {
                Debug.WriteLine("Cannot get property values");
                return(new Dictionary <PropertyKey, object>());
            }

            return(properties);
        }
Beispiel #11
0
        private void AddProperties(IPropertyStore nativePropertyStore)
        {
            // Populate the property collection
            nativePropertyStore.GetCount(out var propertyCount);
            for (uint i = 0; i < propertyCount; i++)
            {
                nativePropertyStore.GetAt(i, out var propKey);

                if (ParentShellObject != null)
                {
                    Items.Add(ParentShellObject.Properties.CreateTypedProperty(propKey));
                }
                else
                {
                    Items.Add(CreateTypedProperty(propKey, NativePropertyStore));
                }
            }
        }
Beispiel #12
0
        private static void PrintChangedProperties(IUISimplePropertySet commandExecutionProperties)
        {
            PropVariant propChangesProperties;

            commandExecutionProperties.GetValue(ref RibbonProperties.FontProperties_ChangedProperties, out propChangesProperties);
            IPropertyStore changedProperties = (IPropertyStore)propChangesProperties.Value;
            uint           changedPropertiesNumber;

            changedProperties.GetCount(out changedPropertiesNumber);

            Debug.WriteLine("");
            Debug.WriteLine("FontControl changed properties:");
            for (uint i = 0; i < changedPropertiesNumber; ++i)
            {
                PropertyKey propertyKey;
                changedProperties.GetAt(i, out propertyKey);
                Debug.WriteLine(RibbonProperties.GetPropertyKeyName(ref propertyKey));
            }
        }
Beispiel #13
0
        /// <summary>
        /// Based on https://docs.microsoft.com/en-us/windows/desktop/medfound/shell-metadata-providers
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void infoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IMFSourceResolver pSourceResolver = null;
            IMFMediaSource    pSource         = null;
            object            pPropsObject    = null;
            var url = this.listView1.SelectedItems[0].Text;

            try
            {
                // Create the source resolver.
                HResult hr = MFExtern.MFCreateSourceResolver(out pSourceResolver);
                Validate(hr);
                if (pSourceResolver == null)
                {
                    throw new Exception("pSourceResolver is null");
                }
                // Get a pointer to the IMFMediaSource interface of the media source.
                hr = pSourceResolver.CreateObjectFromURL(url, MFResolution.MediaSource, null, out pSource);
                Validate(hr);
                if (pSource == null)
                {
                    throw new Exception("pSource is null");
                }

                hr = MFExtern.MFGetService(pSource, MFServices.MF_PROPERTY_HANDLER_SERVICE, typeof(IPropertyStore).GUID, out pPropsObject);
                Validate(hr);
                if (pPropsObject == null)
                {
                    throw new Exception("pPropsObject is null");
                }
                IPropertyStore pProps = pPropsObject as IPropertyStore;

                hr = pProps.GetCount(out int cProps);
                Validate(hr);

                var audioInfo = new AudioInfo();
                var videoInfo = new VideoInfo();

                for (int i = 0; i < cProps; ++i)
                {
                    var key = new MediaFoundation.Misc.PropertyKey();
                    hr = pProps.GetAt(i, key);
                    Validate(hr);

                    using (PropVariant pv = new PropVariant())
                    {
                        hr = pProps.GetValue(key, pv);
                        Validate(hr);
                        FillAudioProperty(audioInfo, key, pv);
                        FillVideoProperty(videoInfo, key, pv);
                    }
                }
                MessageBox.Show("Audio =\n" + audioInfo + ";\nVideo =\n" + videoInfo);
            }
            finally
            {
                if (pSource != null)
                {
                    Marshal.ReleaseComObject(pSource);
                }
                if (pSourceResolver != null)
                {
                    Marshal.ReleaseComObject(pSourceResolver);
                }
                if (pPropsObject != null)
                {
                    Marshal.ReleaseComObject(pPropsObject);
                }
            }
            // MessageBox.Show(url);
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            if (args.Length == 2 && args[0] == "/get")
            {
                var          fp   = args[1];
                IShellLinkW  plnk = (IShellLinkW) new CShellLink();
                IPersistFile ppf  = (IPersistFile)plnk;
                ppf.Load(fp, STGM_READ);
                // http://8thway.blogspot.jp/2012/11/csharp-appusermodelid.html
                IPropertyStore pps = (IPropertyStore)plnk;
                PropVariant    v   = new PropVariant();
                pps.GetValue(ref AppUserModelIDKey, ref v);

                String s = "";
                if (v.vt == VT_BSTR)
                {
                    s = Marshal.PtrToStringUni(v.pVal);
                }
                if (v.vt == VT_LPWSTR)
                {
                    s = Marshal.PtrToStringUni(v.pVal);
                }

                Console.WriteLine(s);
            }
            else if (args.Length == 2 && args[0] == "/list")
            {
                var          fp   = args[1];
                IShellLinkW  plnk = (IShellLinkW) new CShellLink();
                IPersistFile ppf  = (IPersistFile)plnk;
                ppf.Load(fp, STGM_READ);
                IPropertyStore pps = (IPropertyStore)plnk;
                uint           cx;
                pps.GetCount(out cx);
                for (uint x = 0; x < cx; x++)
                {
                    PropertyKey k = new PropertyKey();
                    pps.GetAt(x, ref k);
                    PropVariant v = new PropVariant();
                    pps.GetValue(ref k, ref v);
                    String s = "";
                    if (v.vt == VT_BSTR)
                    {
                        s = Marshal.PtrToStringUni(v.pVal);
                    }
                    if (v.vt == VT_LPWSTR)
                    {
                        s = Marshal.PtrToStringUni(v.pVal);
                    }
                    Console.WriteLine(k.fmtid.ToString("B") + " " + k.pid + " " + v.vt + " " + s);
                }
            }
            else if (args.Length == 3 && args[0] == "/set")
            {
                var          fp   = args[1];
                var          s    = args[2];
                IShellLinkW  plnk = (IShellLinkW) new CShellLink();
                IPersistFile ppf  = (IPersistFile)plnk;
                ppf.Load(fp, STGM_READWRITE);
                // http://8thway.blogspot.jp/2012/11/csharp-appusermodelid.html
                IPropertyStore pps = (IPropertyStore)plnk;
                PropVariant    pv  = new PropVariant {
                    vt   = VT_LPWSTR,
                    pVal = Marshal.StringToBSTR(s)
                };
                pps.SetValue(ref AppUserModelIDKey, ref pv);
                pps.Commit();
                ppf.Save(fp, false);
            }
            else
            {
                helpYa();
            }
        }