【问题标题】:Outlook VSTO CustomPanesIssue.Add - Such Interface is not supportedOutlook VSTO CustomPanesIssue.Add - 不支持此类接口
【发布时间】:2021-08-26 21:52:00
【问题描述】:

我正在开发 Outlook VSTO 插件以在当前打开的窗口顶部显示一条消息。例如,我想在某些条件下尝试“全部回复”时向用户显示一条消息。在电子邮件上它工作正常,但在会议上同样不工作。

案例电子邮件 -(回复、全部回复、新建)

运行良好的代码如下。

     'Starup Event to initialize control objects
            Private Sub ThisAddIn_Startup() Handles Me.Startup
                Try
                    'Insitialize outlook inspector.
                    inspectors = Globals.ThisAddIn.Application.Inspectors
        
                    'Create new inspector
                    AddHandler inspectors.NewInspector, AddressOf inspectors_NewInspector
       
        
                Catch ex As System.Exception
                    'MessageBox.Show(ex.StackTrace)
                End Try
        
            End Sub
    
      
    
    Sub inspectors_NewInspector(inspector As Microsoft.Office.Interop.Outlook.Inspector)
        Try
            subInspector = inspector
    
            Dim mailItem As Outlook.MailItem
            mailItem = DirectCast(inspector.CurrentItem, Outlook.MailItem)
    
            'AddHandler mailItem.Open, AddressOf explorer_onOpen
    
        Catch ex As System.Exception
    
        End Try
    End Sub

      Private Sub explorer_onOpen()
        'I am using Thread to wait few seconds until New Email Windows open.
        'Else message message bar display on the windows which opened and on top. and 
         ' New/Reply email windows takes some time to appear.
        
        Dim thread As New Thread(AddressOf MyBackgroundThread)
        thread.IsBackground = True
        thread.Start()
    End Sub

 Private Sub MyBackgroundThread()
        Try
            'Pause code for 2.5 seconds
            Thread.Sleep(2500)
            MessageBox.Show("Threading")

            _obj = New UserControl2
            Dim _pane1 = Globals.ThisAddIn.CustomTaskPanes.Add(_obj,"Test",Globals.ThisAddIn.Application.ActiveWindow)
           _pane1.Visible=True
        Catch ex As System.Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

但相同的代码不适用于 AppointmentItem。代码如下。只有我在 Open 事件和线程中所做的更改

Sub inspectors_NewInspector(inspector As Microsoft.Office.Interop.Outlook.Inspector)
        Try
            subInspector = inspector            
            Dim appouitmentItem As Outlook.AppointmentItem
            appouitmentItem = DirectCast(inspector.CurrentItem, Outlook.AppointmentItem)

            AddHandler appouitmentItem.Open, AddressOf explorer_onOpen

        Catch ex As System.Exception

        End Try
    End Sub

    Private Sub explorer_onOpen()
        'Thread to display warning message after few seconds
        MessageBox.Show("Thread to display warning message after few seconds")
        Dim thread As New Thread(AddressOf MyBackgroundThread)
        thread.IsBackground = True
        thread.Start()

    End Sub

 Private Sub MyBackgroundThread()
        Try
            'Pause code for 2.5 seconds
            Thread.Sleep(2500)
            MessageBox.Show("Threading")

            _obj = New UserControl2
                Dim _pane1 = Globals.ThisAddIn.CustomTaskPanes.Add(_obj,"Test",Globals.ThisAddIn.Application.ActiveWindow)
               _pane1.Visible=True
        Catch ex As System.Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

我收到错误 无法将 COM 对象类型“System._ComObject”转换为接口类型“Microsoft.VisualStudio.Tools.Office.Runtime.ICustomTaskPaneSite”。此操作失败,因为 IID{} 接口的 COM 组件上的 QueryInterface 调用失败,原因是以下错误:不支持此类接口。

环境: 视觉工作室 2019 办公室 2016

【问题讨论】:

    标签: outlook vsto outlook-addin


    【解决方案1】:

    首先,Outlook 中的检查器窗口无需使用任务窗格。相反,您可以考虑使用Outlook form regions。与传统 Outlook 表单开发相比,表单区域提供了许多增强功能:

    • 自定义任何标准表单的默认页面。
    • 在任何标准表单中最多可添加 12 页。
    • 替换或增强任何标准表单。
    • 在阅读窗格和检查器中显示自定义 UI。

    如需了解更多信息,请参阅Customize form pages and form regions。

    FormRegionInitializing 事件处理程序在表单区域代码文件中公开。您可以使用此事件处理程序来指定 Outlook 是否应显示表单区域。如需更多信息,请参阅Handle form region events。

    您还需要从主线程(UI 线程)运行代码,因为 Outlook 使用单线程单元模型。此外,任何 UI 更改都应从主线程进行。

    【讨论】:

    • 嗨,FormRegion 没有让我选择在顶部显示消息。 FormRegion 仅显示在底部。所以不符合我的要求。虽然 CustomTaskPanes 在线程下的电子邮件中工作,但在线程下的会议中不起作用。外螺纹工作正常
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 2014-07-15
    • 1970-01-01
    • 2019-02-24
    相关资源
    最近更新 更多