Problem: VB.NET Outlook Addin - declare new application object

G

Guest

I have a vb.net outlook addin with the following problem. I have to use the
NEW keyword when declaring my Outlook.Application object. I don't think I
should be using the new keyword, as in all the samples I have look at you
just set a reference to the application object parsed into the connect
procedure. If I don't use the New keyword then I get "object reference not
set" errors.

The reason I'm concerned about this is because when Outlook closes, it takes
quite a while to close fully when my addin is installed. I'm wondering if
having to declare the application as new is the cause of this.

Here is a sample of my code:

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 Outlook.Application
....
oApp = CType(application, Outlook.Application)
....
m_BaseClass.InitHandler(oApp, MyProgID)
....
End Sub

Public Class OutAddin
Dim WithEvents objOutlook As New Outlook.Application

Friend Sub InitHandler(ByVal oApp As Outlook.Application, ByVal strPID As
String)
Try
objOutlook = oApp
....

Any suggestions would be appreciated.

Thanks
Jeanine
 
H

Helmut Obertanner

Hello Jeanine,

i would declare the applicationobject as classwide variable in connect,
so you keep an instance to the initial Application Object until you
disconnect.

If you have created your AddIn with VisualStudio Wizard,
remove the reference to the Office.dll and add a new reference to COM Office
Object.

If you pass the Application Object to another Class, use byref.

I posted a small VB AddIn example here:
http://www.outlookcode.com/codedetail.aspx?id=771

However, I'm more familiary with C#
Hope this helps,

Greets, Helmut Obertanner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top