在为 Visual Studio 2010 开发插件时,以下行失败:
CommandBarEvents handler = (EnvDTE.CommandBarEvents)m_VSStudio.DTE.Events.get_CommandBarEvents(popup);
更新:忘了告诉 m_VSStudio 是 DTE2 类型
其中 popup 是 CommandBarPopup 类型(对于 CommandBarControl 类型它可以工作)
该行因此异常而失败:
System.Runtime.InteropServices.COMException (0x80020003): Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
完全相同的行在 Visual Studio 2008 中工作。
该行的目的是获得一个处理点击事件的处理程序,当单击弹出窗口时。
经过一番搜索,我找到了这个链接:http ://connect.microsoft.com/VisualStudio/feedback/details/524335/events-get-commandbarevents-exception-on-submenus-reproducible-bug-addin
这基本上表明这是一个已知的错误,不会被修复,因为有一个解决方法。但不幸的是,它没有说明解决方法:(
如果有人对解决方法有一个好主意,我会非常高兴?
我想听点击事件的原因是因为我想在某些条件下显示或隐藏子菜单项(CommandBarControl),当一个人点击一个菜单(CommandBarPopup)时。
因此,使用 click 事件以外的其他方法的解决方法也将受到赞赏。