Shared add-in with user control

ptmujeebrahman

New member
Joined
Sep 17, 2007
Messages
1
Programming Experience
1-3
I want to create shared add-in stuff for outlook 2003. In the new mail item I need a user control containing some check boxes ,
I can show what I did in Connect.vb
VB.NET:
imports Extensibility
Imports System.Runtime.InteropServices
Imports System
Imports Microsoft.Office.Core
Imports OutLook = Microsoft.Office.Interop.Outlook
Imports office = Microsoft.Office.Core

<GuidAttribute("E37011E5-0A47-4525-B684-56C385A057B7"), ProgIdAttribute("OutLook_v103.Connect")> _
Public Class Connect
	
	Implements Extensibility.IDTExtensibility2

	Dim applicationObject as Object
    Dim addInInstance As Object
    Dim otApp As OutLook.Application
    Dim cba As office._CommandBarActiveX
    Dim cmm As office.CommandBar
    Dim myInspector As OutLook.Inspectors
    Private myMissing As Object = System.Reflection.Missing.Value
	
	Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
	End Sub
	
	Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
	End Sub
	
	Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
        myInspector = CType(otApp.Inspectors, OutLook.Inspectors)
        AddHandler myInspector.NewInspector, AddressOf myInspectors_NewInspector
    End Sub
	
	Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
	End Sub
	
	Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
		applicationObject = application
        addInInstance = addInInst
        otApp = CType(application, OutLook.Application)
	End Sub
    Private Sub myInspectors_NewInspector(ByVal inspector As Microsoft.Office.Interop.Outlook.Inspector)
        Try
            Dim Item As Object = inspector.CurrentItem
            ' Check the ItemsType
            If TypeOf Item Is OutLook.MailItem Then
                cmm = inspector.CommandBars.Add("somename", myMissing, myMissing, True)

                cba = CType(cmm.Controls.Add(22, myMissing, myMissing, myMissing, True), Microsoft.Office.Core._CommandBarActiveX)
                cba.ControlCLSID = "{879F1CBB-2B11-4bc3-9E80-7643921F659C}"
                cba.Visible = True
                cba.EnsureControl()
                cba.Height = 188
                cba.Width = 1024
                Dim OLobj As IOutLookTest
                OLobj = CType(cba, IOutLookTest)
                MsgBox(OLobj.test2("gg"))
    System.Runtime.InteropServices.Marshal.ReleaseComObject(cba)
                GC.Collect()
                cmm.Visible = True
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
I add user control and code part as follows
VB.NET:
Imports System.Runtime.InteropServices
<GuidAttribute("C86D1E46-8D45-44ee-8C2E-2916D4C6F664")> _
<ComVisible(True)> _
<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IOutLookTest
    Function test2(ByVal aa As String) As String
End Interface
<GuidAttribute("879F1CBB-2B11-4bc3-9E80-7643921F659C"), ProgIdAttribute("UserControl1.UserControl")> _
<ClassInterface(ClassInterfaceType.AutoDual)> _
<ComVisible(True)> _
Partial Public Class OutLookControl
    Implements IOutLookTest
    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub
    <ComVisible(True)> _
       Public Function test2(ByVal aa As String) As String Implements IOutLookTest.test2

        test2 = "bb->" & aa

    End Function

End Class
I run this solution and open outlook 2003 then open new mail item, the following errors occur
---------------------------
OutLook_v103
---------------------------
Unable to cast COM object of type 'System.__ComObject' to interface type 'OutLook_v103.IOutLookTest'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{C86D1E46-8D45-44EE-8C2E-2916D4C6F664}'
failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
---------------------------
I think problem in this portion OLobj = CType(cba, IOutLookTest)
Anybody can help me? Will be greatly appreciated
Thanks
Mujeeb
 
Last edited by a moderator:
Back
Top