Outlook add-in 插件.Net开发经验-补充(1)

** Outlook add-in 插件 .Net 开发经验 - 补充( 1 ) **

这次补充了些东西,把原文扩充了一些,为了看着方便,直接合并在了一起。

第一次写这玩意,记录些开发中的过程, .net 开发设置要比在 VB 里复杂一些,要把 office 的对象用 ms 提供的工具包装一下,才能在 .Net 开发环境里使用。

开发环境设置:

我的开发环境: Windows2K professional + Office XP

Office 每个版本的对象,不尽相同,一般新版本兼容旧版本,也有可能会废弃某些对象的接口。我看过 Office XP , Office2000 的 outlook 对象, Outlook XP 比 Outlook2000 要多出一些对象和接口函数。

OfficeXP 需要配置 ms 提供的设置文件,具体可看 ( 下载 ) 。

Office 2003 直接在 Office 安装包里,安装 .Net 开发支持,直接可以在 VS.Net 里开发了。

我使用 VB.Net 开发,这样直接对 Outlook 对象编程比较方便(使用 withevents ),用 C# 的话,需要自定义事件参数,设置 delegate 。

对 Outlook 进行二次开发,可能用到 CDO1.21 对象,这个不是必需的,按个人需要。使用 CDO1.21 对象,可以使用一些较为核心的 Outlook 方法。这些方法,属性在 Outlook 对象里可能无法使用。

如果需要更直接的设置,获取 Outlook 对象,可以对 MAPI32.dll 提供的 api 接口,进行控制,可以最大限度的操纵 Outlook 。这些接口直接使用 C++ 编程最方便,我没有具体的做过,只测试了一些,也就不多说了。

开发过程简介:

在 vs.net 里,其他项目 à 扩展性项目 à 共享的外接程序。

选择语言:

选择外接程序的加载到的主程序,这里我只选择 outlook :

程序会帮我们自动生成一个 Addin 项目,包含一个 Connect.vb 文件,打开看看。

Implements Extensibility.IDTExtensibility2 的接口。

象这样,我们就可以取得 outlook的application对象,操纵Outlook。

** 取得 outlook的application对象,操纵Outlook **


_ Dim _ _ m_oAddin As olAddin _

_ 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 _

_ _

_ Dim oApp As myOutlook.Application _

_ Dim oType As Type _

_ Dim GetProgID As Object _

_ Dim MyProgID As String _

_ Dim oArgs As Object () _

_ _

_ Try _

_ m_oAddin = New olAddin _

_ 'Use InvokeMember to get ProgID of addInInst object _

_ oType = addInInst.GetType _

_ GetProgID = oType.InvokeMember("ProgID", _ _

_ BindingFlags.Public Or BindingFlags.GetField Or BindingFlags.GetProperty, _ _

_ Nothing , _ _

_ addInInst, _ _

_ oArgs) _

_ MyProgID = CType (GetProgID, String ) _

_ oApp = CType (application, myOutlook.Application) _

_ 'Don't call InitHandler if Explorers.Count = 0 and Inspectors.Count = 0 _

_ If oApp.Explorers.Count = 0 And oApp.Inspectors.Count = 0 Then _

_ Exit Sub _

_ End If _

_ ' Initialize COMAddin object with this connect object to allow _

_ ' external clients to get access to exposed features _

_ oApp.COMAddIns.Item(MyProgID.ToString).Object = Me _

_ 'Call InitHandler _

_ m_oAddin.InitHandler(oApp, MyProgID) _

_ Catch ex As SystemException _

_ _

_ End Try _

_ End _ _ Sub _

_ _

当然也可以把所有的对 outlook的操作,放在一个单独的类中处理: _ m_oAddin.InitHandler(oApp, MyProgID) _

Published At
Categories with Web编程
Tagged with
comments powered by Disqus