コード例 #1
0
ファイル: CALPOLESTRTests.cs プロジェクト: lonitra/winforms
        public void CALPOLESTR_ConvertAndFree_EmptyStruct()
        {
            Ole32.CALPOLESTR ca = default;

            string?[] values = ca.ConvertAndFree();
            Assert.Empty(values);
        }
コード例 #2
0
ファイル: CALPOLESTRTests.cs プロジェクト: lonitra/winforms
        public void CALPOLESTR_ConvertAndFree_SingleItem()
        {
            Ole32.CALPOLESTR ca = CreateStringVector("Swizzle");

            string?[] values = ca.ConvertAndFree();
            Assert.Equal(1, values.Length);
            Assert.Equal("Swizzle", values[0]);
        }
コード例 #3
0
ファイル: CALPOLESTRTests.cs プロジェクト: lonitra/winforms
        public void CALPOLESTR_ConvertAndFree_FreesMemory()
        {
            List<IntPtr> allocations = new();
            Ole32.CALPOLESTR ca = CreateStringVector(allocations, "Sweet", "Potato");

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

            string?[] values = ca.ConvertAndFree();
            Assert.Equal(2, values.Length);
            Assert.Equal("Sweet", values[0]);
            Assert.Equal("Potato", values[1]);

            foreach (IntPtr allocation in allocations)
            {
                Assert.Contains(allocation, tracker.FreedBlocks);
            }
        }
コード例 #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);
                }
            }
        }