gpt4 book ai didi

c# - 如何识别 COM 库中的 "default member"?

转载 作者:行者123 更新时间:2023-11-30 18:21:09 25 4
gpt4 key购买 nike

我正在使用 ITypeInfo API 将 COM 类型库“翻译”为我的应用程序使用的“声明”对象。

“声明”的特征之一是“属性”——我能够判断属性“声明”何时应该具有 {name}.VB_UserMemId = -4 属性(即当它是一个 _NewEnum 不可浏览的属性时;我还可以判断属性何时被隐藏。

我没能说明的是,当成员是该类型的默认成员 时。根据 FUNCFLAG_FDEFAULTBIND ( MSDN ) 的描述:

The function that best represents the object. Only one function in a type information can have this attribute.

...这听起来非常非常像我正在寻找的东西。然而,在我遍历少数类型库(包括 VBA 标准库和整个 Excel 对象模型)的所有成员中,完全没有有那个标志。

我期待这段代码为 Collection.Item 之类的东西调用 AddDefaultMemberAttribute,它是类型的默认成员 - 但没有骰子.我没有检查正确的标志/值吗?

var attributes = new Attributes();
if (((FUNCFLAGS)memberDescriptor.wFuncFlags) != 0)
{
if (memberName == "_NewEnum" && ((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FNONBROWSABLE))
{
attributes.AddEnumeratorMemberAttribute(memberName);
}
else if (((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FHIDDEN))
{
attributes.AddHiddenMemberAttribute(memberName);
}
else if (((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FDEFAULTBIND))
{
// bug: none of the 30K+ reflected members have this flag on??
attributes.AddDefaultMemberAttribute(memberName);
}
}

最佳答案

删除 wFuncFlags != 0 的检查,您将通过该检查跳过大量成员,其中很多是您真正感兴趣的。

现在检查 memid == 0 ( thanks @HansPassant )

else if (memberDescriptor.memid == 0)
{
attributes.AddDefaultMemberAttribute(memberName);
Debug.WriteLine("Default member found: {0}.{1} ({2} / {3})", moduleDeclaration.IdentifierName, memberName, memberDeclarationType, (VarEnum)memberDescriptor.elemdescFunc.tdesc.vt);
}

这个小小的 Debug.WriteLine 指令产生了这个输出(被截断,以适应后置字符限制):

Default member found: _ErrObject.Number (PropertyGet / VT_I4)
Default member found: _ErrObject.Number (PropertyLet / VT_VOID)
Default member found: _Collection.Item (Function / VT_VARIANT)
Default member found: Adjustments.Item (PropertyGet / VT_R4)
Default member found: Adjustments.Item (PropertyLet / VT_VOID)
Default member found: ColorFormat.RGB (PropertyGet / VT_USERDEFINED)
Default member found: ColorFormat.RGB (PropertyLet / VT_VOID)
Default member found: ShapeNodes.Item (Function / VT_PTR)
Default member found: DiagramNodes.Item (Function / VT_PTR)
Default member found: DiagramNodeChildren.Item (Function / VT_PTR)
Default member found: IWindows._Default (PropertyGet / VT_HRESULT)
Default member found: _Application._Default (PropertyGet / VT_BSTR)
Default member found: IRange._Default (PropertyGet / VT_HRESULT)
Default member found: IRange._Default (PropertyLet / VT_HRESULT)
Default member found: Sheets._Default (PropertyGet / VT_DISPATCH)
Default member found: IHPageBreaks._Default (PropertyGet / VT_HRESULT)
Default member found: IVPageBreaks._Default (PropertyGet / VT_HRESULT)
Default member found: IRecentFiles._Default (PropertyGet / VT_HRESULT)
Default member found: IStyle._Default (PropertyGet / VT_HRESULT)
Default member found: IStyles._Default (PropertyGet / VT_HRESULT)
Default member found: IBorders._Default (PropertyGet / VT_HRESULT)
Default member found: IAddIns._Default (PropertyGet / VT_HRESULT)
Default member found: IToolbars._Default (PropertyGet / VT_HRESULT)
Default member found: IToolbarButtons._Default (PropertyGet / VT_HRESULT)
Default member found: IAreas._Default (PropertyGet / VT_HRESULT)
Default member found: Workbooks._Default (PropertyGet / VT_PTR)
Default member found: IMenuBars._Default (PropertyGet / VT_HRESULT)
Default member found: IMenus._Default (PropertyGet / VT_HRESULT)
Default member found: IMenuItems._Default (PropertyGet / VT_HRESULT)
Default member found: ICharts._Default (PropertyGet / VT_HRESULT)
Default member found: IDrawingObjects._Default (PropertyGet / VT_HRESULT)
Default member found: IDrawingObjects._Default (PropertyLet / VT_HRESULT)
Default member found: IPivotCaches._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotFormula._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotFormula._Default (PropertyLet / VT_HRESULT)
Default member found: IPivotFormulas._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotTable._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotTable._Default (PropertyLet / VT_HRESULT)
Default member found: IPivotField._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotField._Default (PropertyLet / VT_HRESULT)
Default member found: ICalculatedFields._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotItem._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotItem._Default (PropertyLet / VT_HRESULT)
Default member found: ICalculatedItems._Default (PropertyGet / VT_HRESULT)
Default member found: IDialogs._Default (PropertyGet / VT_HRESULT)
Default member found: ICheckBox._Default (PropertyGet / VT_HRESULT)
Default member found: ICheckBox._Default (PropertyLet / VT_HRESULT)
Default member found: ICheckBoxes._Default (PropertyGet / VT_HRESULT)
Default member found: ICheckBoxes._Default (PropertyLet / VT_HRESULT)
Default member found: IOptionButton._Default (PropertyGet / VT_HRESULT)
Default member found: IOptionButton._Default (PropertyLet / VT_HRESULT)
Default member found: IOptionButtons._Default (PropertyGet / VT_HRESULT)
Default member found: IOptionButtons._Default (PropertyLet / VT_HRESULT)
Default member found: IScrollBar._Default (PropertyGet / VT_HRESULT)
Default member found: IScrollBar._Default (PropertyLet / VT_HRESULT)
Default member found: IScrollBars._Default (PropertyGet / VT_HRESULT)
Default member found: IScrollBars._Default (PropertyLet / VT_HRESULT)
Default member found: IListBox._Default (PropertyGet / VT_HRESULT)
Default member found: IListBox._Default (PropertyLet / VT_HRESULT)
Default member found: IListBoxes._Default (PropertyGet / VT_HRESULT)
Default member found: IListBoxes._Default (PropertyLet / VT_HRESULT)
Default member found: IDropDown._Default (PropertyGet / VT_HRESULT)
Default member found: IDropDown._Default (PropertyLet / VT_HRESULT)
Default member found: IDropDowns._Default (PropertyGet / VT_HRESULT)
Default member found: IDropDowns._Default (PropertyLet / VT_HRESULT)
Default member found: ISpinner._Default (PropertyGet / VT_HRESULT)
Default member found: ISpinner._Default (PropertyLet / VT_HRESULT)
Default member found: ISpinners._Default (PropertyGet / VT_HRESULT)
Default member found: ISpinners._Default (PropertyLet / VT_HRESULT)
Default member found: IPanes._Default (PropertyGet / VT_HRESULT)
Default member found: IGroupObject._Default (PropertyGet / VT_HRESULT)
Default member found: IGroupObject._Default (PropertyLet / VT_HRESULT)
Default member found: IGroupObjects._Default (PropertyGet / VT_HRESULT)
Default member found: IGroupObjects._Default (PropertyLet / VT_HRESULT)
Default member found: IModules._Default (PropertyGet / VT_HRESULT)
Default member found: IDialogSheets._Default (PropertyGet / VT_HRESULT)
Default member found: IWorksheets._Default (PropertyGet / VT_HRESULT)
Default member found: INames._Default (Function / VT_HRESULT)
Default member found: IName._Default (PropertyGet / VT_HRESULT)
Default member found: IChartObjects._Default (Function / VT_HRESULT)
Default member found: ICustomViews._Default (PropertyGet / VT_HRESULT)
Default member found: IFormatConditions._Default (PropertyGet / VT_HRESULT)
Default member found: IComments._Default (PropertyGet / VT_HRESULT)
Default member found: IQueryTables._Default (PropertyGet / VT_HRESULT)
Default member found: IParameters._Default (PropertyGet / VT_HRESULT)
Default member found: IODBCErrors._Default (PropertyGet / VT_HRESULT)
Default member found: IHyperlinks._Default (PropertyGet / VT_HRESULT)
Default member found: IFilters._Default (PropertyGet / VT_HRESULT)
Default member found: IChartColorFormat._Default (PropertyGet / VT_HRESULT)
Default member found: IAxes._Default (Function / VT_HRESULT)
Default member found: IPoints._Default (Function / VT_HRESULT)
Default member found: ISeriesCollection._Default (Function / VT_HRESULT)
Default member found: IDataLabels._Default (Function / VT_HRESULT)
Default member found: ILegendEntries._Default (Function / VT_HRESULT)
Default member found: ITrendlines._Default (Function / VT_HRESULT)
Default member found: IShapes._Default (Function / VT_HRESULT)
Default member found: IShapeRange._Default (Function / VT_HRESULT)
Default member found: IGroupShapes._Default (Function / VT_HRESULT)
Default member found: IControlFormat._Default (PropertyGet / VT_HRESULT)
Default member found: IControlFormat._Default (PropertyLet / VT_HRESULT)
Default member found: IPublishObjects._Default (PropertyGet / VT_HRESULT)
Default member found: IOLEDBErrors._Default (PropertyGet / VT_HRESULT)
Default member found: IPhonetics._Default (PropertyGet / VT_HRESULT)
Default member found: CubeFields._Default (PropertyGet / VT_PTR)
Default member found: IUsedObjects._Default (PropertyGet / VT_HRESULT)
Default member found: ICustomProperties._Default (PropertyGet / VT_HRESULT)
Default member found: ICustomProperty._Default (PropertyGet / VT_HRESULT)
Default member found: ICalculatedMembers._Default (PropertyGet / VT_HRESULT)
Default member found: ICalculatedMember._Default (PropertyGet / VT_HRESULT)
Default member found: IWatches._Default (PropertyGet / VT_HRESULT)
Default member found: IErrors._Default (PropertyGet / VT_HRESULT)
Default member found: ISmartTagAction._Default (PropertyGet / VT_HRESULT)
Default member found: ISmartTagActions._Default (PropertyGet / VT_HRESULT)
Default member found: ISmartTag._Default (PropertyGet / VT_HRESULT)
Default member found: ISmartTags._Default (PropertyGet / VT_HRESULT)
Default member found: ISmartTagRecognizer._Default (PropertyGet / VT_HRESULT)
Default member found: ISmartTagRecognizers._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotItemList._Default (PropertyGet / VT_HRESULT)
Default member found: IAllowEditRanges._Default (PropertyGet / VT_HRESULT)
Default member found: IUserAccessList._Default (PropertyGet / VT_HRESULT)
Default member found: IListObjects._Default (PropertyGet / VT_HRESULT)
Default member found: IListObject._Default (PropertyGet / VT_HRESULT)
Default member found: IListColumns._Default (PropertyGet / VT_HRESULT)
Default member found: IListColumn._Default (PropertyGet / VT_HRESULT)
Default member found: IListRows._Default (PropertyGet / VT_HRESULT)
Default member found: IXmlNamespace._Default (PropertyGet / VT_HRESULT)
Default member found: IXmlNamespaces._Default (PropertyGet / VT_HRESULT)
Default member found: IXmlDataBinding._Default (PropertyGet / VT_HRESULT)
Default member found: IXmlSchemas._Default (PropertyGet / VT_HRESULT)
Default member found: IXmlMap._Default (PropertyGet / VT_HRESULT)
Default member found: IXmlMaps._Default (PropertyGet / VT_HRESULT)
Default member found: IListDataFormat._Default (PropertyGet / VT_HRESULT)
Default member found: IXPath._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotLineCells._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotLines._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotFilters._Default (PropertyGet / VT_HRESULT)
Default member found: IWorkbookConnection._Default (PropertyGet / VT_HRESULT)
Default member found: IWorkbookConnection._Default (PropertyLet / VT_HRESULT)
Default member found: IConnections._Default (PropertyGet / VT_HRESULT)
Default member found: ISheetViews._Default (PropertyGet / VT_HRESULT)
Default member found: IActions._Default (PropertyGet / VT_HRESULT)
Default member found: IColorScaleCriteria._Default (PropertyGet / VT_HRESULT)
Default member found: IIconCriteria._Default (PropertyGet / VT_HRESULT)
Default member found: IIconSet._Default (PropertyGet / VT_HRESULT)
Default member found: IIconSets._Default (PropertyGet / VT_HRESULT)
Default member found: IRanges._Default (PropertyGet / VT_HRESULT)
Default member found: IPages._Default (PropertyGet / VT_HRESULT)
Default member found: IServerViewableItems._Default (PropertyGet / VT_HRESULT)
Default member found: ITableStyleElements._Default (PropertyGet / VT_HRESULT)
Default member found: ITableStyle._Default (PropertyGet / VT_HRESULT)
Default member found: ITableStyles._Default (PropertyGet / VT_HRESULT)
Default member found: ISortFields._Default (PropertyGet / VT_HRESULT)
Default member found: IColorStops._Default (PropertyGet / VT_HRESULT)
Default member found: IFileExportConverters._Default (PropertyGet / VT_HRESULT)
Default member found: IAddIns2._Default (PropertyGet / VT_HRESULT)
Default member found: ISparklineGroups._Default (PropertyGet / VT_HRESULT)
Default member found: IPivotTableChangeList._Default (PropertyGet / VT_HRESULT)
Default member found: ISlicerCaches._Default (PropertyGet / VT_HRESULT)
Default member found: ISlicerCacheLevels._Default (PropertyGet / VT_HRESULT)
Default member found: ISlicers._Default (PropertyGet / VT_HRESULT)
Default member found: ISlicerItems._Default (PropertyGet / VT_HRESULT)
Default member found: ISlicerPivotTables._Default (PropertyGet / VT_HRESULT)
Default member found: IProtectedViewWindows._Default (PropertyGet / VT_HRESULT)
Default member found: IProtectedViewWindow._Default (PropertyGet / VT_HRESULT)
Default member found: Windows._Default (PropertyGet / VT_PTR)
Default member found: Range._Default (PropertyGet / VT_VARIANT)
Default member found: Range._Default (PropertyLet / VT_VOID)
Default member found: HPageBreaks._Default (PropertyGet / VT_PTR)
Default member found: VPageBreaks._Default (PropertyGet / VT_PTR)
Default member found: RecentFiles._Default (PropertyGet / VT_PTR)
Default member found: Style._Default (PropertyGet / VT_BSTR)
Default member found: Styles._Default (PropertyGet / VT_PTR)
Default member found: Borders._Default (PropertyGet / VT_PTR)
Default member found: AddIns._Default (PropertyGet / VT_PTR)
Default member found: Toolbars._Default (PropertyGet / VT_PTR)
Default member found: ToolbarButtons._Default (PropertyGet / VT_PTR)
Default member found: Areas._Default (PropertyGet / VT_PTR)
Default member found: MenuBars._Default (PropertyGet / VT_PTR)
Default member found: Menus._Default (PropertyGet / VT_PTR)
Default member found: MenuItems._Default (PropertyGet / VT_DISPATCH)
Default member found: Charts._Default (PropertyGet / VT_DISPATCH)
Default member found: DrawingObjects._Default (PropertyGet / VT_I4)
Default member found: DrawingObjects._Default (PropertyLet / VT_VOID)
Default member found: PivotCaches._Default (PropertyGet / VT_PTR)
Default member found: PivotFormula._Default (PropertyGet / VT_BSTR)
Default member found: PivotFormula._Default (PropertyLet / VT_VOID)
Default member found: PivotFormulas._Default (PropertyGet / VT_PTR)
Default member found: PivotTable._Default (PropertyGet / VT_BSTR)
Default member found: PivotTable._Default (PropertyLet / VT_VOID)
Default member found: PivotField._Default (PropertyGet / VT_BSTR)
Default member found: PivotField._Default (PropertyLet / VT_VOID)
Default member found: CalculatedFields._Default (PropertyGet / VT_PTR)
Default member found: PivotItem._Default (PropertyGet / VT_BSTR)
Default member found: PivotItem._Default (PropertyLet / VT_VOID)
Default member found: CalculatedItems._Default (PropertyGet / VT_PTR)
Default member found: Dialogs._Default (PropertyGet / VT_PTR)
Default member found: CheckBox._Default (PropertyGet / VT_I4)
Default member found: CheckBox._Default (PropertyLet / VT_VOID)
Default member found: CheckBoxes._Default (PropertyGet / VT_I4)
Default member found: CheckBoxes._Default (PropertyLet / VT_VOID)
Default member found: OptionButton._Default (PropertyGet / VT_I4)
Default member found: OptionButton._Default (PropertyLet / VT_VOID)
Default member found: OptionButtons._Default (PropertyGet / VT_I4)
Default member found: OptionButtons._Default (PropertyLet / VT_VOID)
Default member found: ScrollBar._Default (PropertyGet / VT_I4)
Default member found: ScrollBar._Default (PropertyLet / VT_VOID)
Default member found: ScrollBars._Default (PropertyGet / VT_I4)
Default member found: ScrollBars._Default (PropertyLet / VT_VOID)
Default member found: ListBox._Default (PropertyGet / VT_I4)
Default member found: ListBox._Default (PropertyLet / VT_VOID)
Default member found: ListBoxes._Default (PropertyGet / VT_I4)
Default member found: ListBoxes._Default (PropertyLet / VT_VOID)
Default member found: DropDown._Default (PropertyGet / VT_I4)
Default member found: DropDown._Default (PropertyLet / VT_VOID)
Default member found: DropDowns._Default (PropertyGet / VT_I4)
Default member found: DropDowns._Default (PropertyLet / VT_VOID)
Default member found: Spinner._Default (PropertyGet / VT_I4)
Default member found: Spinner._Default (PropertyLet / VT_VOID)
Default member found: Spinners._Default (PropertyGet / VT_I4)
Default member found: Spinners._Default (PropertyLet / VT_VOID)
...

因此,您得到了您要查找的 Collection.ItemErrObject.Number。 [其他] 现在的问题是,如何获取此 _Default 指向的成员的名称,对于那里几乎所有其他默认成员。

但这只是一个开始。

关于c# - 如何识别 COM 库中的 "default member"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36041181/

25 4 0
文章推荐: c# - 使用 ASP.NET MVC 应用程序定期插入 Azure 数据库
文章推荐: c# - 我如何从 Func 转换为 Func c#
文章推荐: C#类列表之间的区别