Interface Implementation

Shared add-ins implement the IDTExtensibility2 interface. This model is loosely coupled, meaning that it can be loaded into multiple hosts (Word, Excel, Outlook, etc.), and the host is determined at run time in the OnConnection method. The OnConnection method is one of five methods available (some of which are seldom used) in add-ins that implement IDTExtensibility2.

VSTO add-ins for Outlook implement an IStartup interface. VSTO add-ins are strongly coupled, and the IStartup interface has only two methods: Startup and Shutdown. Typically, you handle initialization in the Startup event handler, and cleanup is handled in the Shutdown event handler. Figure 10.2 shows the methods that are created when you create a new shared add-in that implements IDTExtensibility2, and the methods that are created when you create a new Outlook add-in that implements IStartup.

Conwïtvfc Pie System (MyAddnlSeiup) Start Pao*

» X

] (General)

_»J |, (Declarations)

Public Class Connect

Implements Extensibility.IDTExtensibllityS

Dira opplicationCbJect as Object DIM addlnrnstance as object

Public Sub OnAddlnslTpdate(S'/Sef custom As System.Array] Implements Extensibility.IDTExtensibilityi End Sub

Public Sub OnStartuncomplete[ByRe£ custom As System,Array) Implements Extensibility.IDTExtensibil: End Sub

Public Sub OnDisconnection(ByVal SerooveSode As Excenaibility.ext DisconnectRode, EyP.ei custom JLs Î End Sub

Public Sub OnConnection(ByVal application A3 Ctoject, ByVal cottnectKode As Extensibility.ext_Connet applicationCtaJect ■ application addlnlnstaoce - addlnlnst

End Sub

ThiiApplkatnn.vb* FfeS

ystem (0. ..otAddru

¡Setup) Stat Page

- X

.(General)

_»J |£J(Oeel«r«Uora)

Z.

Private Sub TbisApplic«ion_Star tup (ByVal sender As Object, ByVal e As System ■ Event Arçrs] Handles He-Startup

Private Sub ThisApplicatioû_Shutdoim(ByVal sender As Object, ByVal e As System.EventArgs) Handles He.Shutdown

End Sub

End class

Figure 10.2. Methods in a shared add-in (top) versus a VSTO Outlook add-in

0 0

Post a comment