private int GetCount()
        {
            uint result;

            Marshal.ThrowExceptionForHR(_property.GetCount(out result));
            return((int)result);
        }
Esempio n. 2
0
        private int GetCount()
        {
            uint count;

            HResult.Try(_propertyStoreInterface.GetCount(out count));
            return((int)count);
        }
Esempio n. 3
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);
        }
Esempio n. 5
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));
            }
        }
Esempio n. 6
0
        private void AddProperties(IPropertyStore nativePropertyStore)
        {
            uint        propertyCount;
            PropertyKey propKey;

            // Populate the property collection
            nativePropertyStore.GetCount(out propertyCount);
            for (uint i = 0; i < propertyCount; i++)
            {
                nativePropertyStore.GetAt(i, out propKey);

                if (this.ParentShellObject != null)
                {
                    this.Items.Add(this.ParentShellObject.Properties.CreateTypedProperty(propKey));
                }
                else
                {
                    this.Items.Add(CreateTypedProperty(propKey, this.NativePropertyStore));
                }
            }
        }
Esempio n. 7
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();
            }
        }