Esempio n. 1
0
        public void CADWORD_ConvertAndFree_EmptyStruct()
        {
            Ole32.CADWORD ca = default;

            uint[] values = ca.ConvertAndFree();
            Assert.Empty(values);
        }
Esempio n. 2
0
        public void CADWORD_ConvertAndFree_SingleItem()
        {
            Ole32.CADWORD ca = CreateIntVector(2020);

            uint[] values = ca.ConvertAndFree();
            Assert.Equal(1, values.Length);
            Assert.Equal(2020u, values[0]);
        }
Esempio n. 3
0
        public void CADWORD_ConvertAndFree_FreesMemory()
        {
            List <IntPtr> allocations = new();

            Ole32.CADWORD ca = CreateIntVector(allocations, 1970, 1999);

            MallocSpy.FreeTracker tracker = new();
            using MallocSpyScope scope = new(tracker);

            uint[] values = ca.ConvertAndFree();
            Assert.Equal(2, values.Length);
            Assert.Equal(1970u, values[0]);
            Assert.Equal(1999u, values[1]);

            foreach (IntPtr allocation in allocations)
            {
                Assert.Contains(allocation, tracker.FreedBlocks);
            }
        }
Esempio n. 4
0
        private unsafe void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent)
        {
            if (sender.TargetObject is not Oleaut32.IPerPropertyBrowsing ppb)
            {
                return;
            }

            // check for enums
            Ole32.CALPOLESTR caStrings = default;
            Ole32.CADWORD    caCookies = default;

            HRESULT hr;

            try
            {
                hr = ppb.GetPredefinedStrings(sender.DISPID, &caStrings, &caCookies);
            }
            catch (ExternalException ex)
            {
                hr = (HRESULT)ex.ErrorCode;
                Debug.Fail($"An exception occurred inside IPerPropertyBrowsing::GetPredefinedStrings(dispid={sender.DISPID}), object type={new ComNativeDescriptor().GetClassName(ppb)}");
            }

            // Terminate the existing editor if we created the current one so if the items have disappeared,
            // we don't hold onto the old items.
            if (gveevent.TypeConverter is Com2IPerPropertyEnumConverter)
            {
                gveevent.TypeConverter = null;
            }

            if (hr == HRESULT.S_OK)
            {
                string[] names   = caStrings.ConvertAndFree();
                uint[]   cookies = caCookies.ConvertAndFree();

                if (names.Length > 0 && cookies.Length > 0)
                {
                    gveevent.TypeConverter = new Com2IPerPropertyEnumConverter(new Com2IPerPropertyBrowsingEnum(sender, names, cookies));
                }
            }
            else
            {
                // If we didn't get any strings, try the proppage editor
                //
                // This is a bit of a backwards-compat work around. Many older ActiveX controls will show a
                // property page for all properties since the old grid would only put up the [...] button for
                // "(Custom)".  If we have a conversion editor, don't allow this to override it.

                if (sender.ConvertingNativeType)
                {
                    return;
                }

                Guid guid = GetPropertyPageGuid(ppb, sender.DISPID);

                if (!Guid.Empty.Equals(guid))
                {
                    gveevent.TypeEditor = new Com2PropertyPageUITypeEditor(sender, guid, (UITypeEditor)gveevent.TypeEditor);
                }
            }
        }