How to disconnect Application.COMAddIns.Item().Object?

  • Thread starter Thread starter Kukulkan
  • Start date Start date
K

Kukulkan

Hello,

To access functions of my AddIn from external, I followed KB Article
http://support.microsoft.com/?kbid=240768 and set a reference at
start:

Application.COMAddIns.Item("MyAddInName.Connect").Object =
ConnectClass

It works great now, but after this, outlook does not close anymore
(stays in taskmanager).

I try'd to disconnect this relationship using the following methods in
my Explorer.Close event:

Application.COMAddIns.Item("MyAddInName.Connect").Object = Nothing
Set Application.COMAddIns.Item("MyAddInName.Connect").Object = Nothing

It does not work. Every time I get an error like 80004005 "method
'object' for object 'ComAddIn' failed".

The following does not help, too:
Application.COMAddIns.Item("MyAddInName.Connect").Connect = False

No effect at all :-(

How to release this connection to my class to allow outlook closing?

Kukulkan
 
Is this VB.NET or VB6? You don't use Set in VB.NET. You also can't
disconnect an addin from within the addin's code, as Connect = False would
try to do.

Normally you never set that to Nothing, it's not necessary and will fire an
exception. What I usually do is to declare an Office.COMAddIn object at
class level in my Connect class and in the OnConnection() event I assign
that from the addInInst object passed in OnConnection(), then I set that
object's Object property to Me.

So in VB.NET it would be something like this:

' class level
Private addinInstance As Office.COMAddIn

' in OnConnection
addinInstance = TryCast(addInInst, Office.COMAddIn)

addinInstance.Object = Me

I don't release that in my teardown code, which is fired when the last
Explorer closes, there's an initialization error, OnDisconnect() or
OnBeginShutDown() fire.

If Outlook isn't exiting there's more likely to be various other Outlook or
Office objects not being released.
 
Hi Ken,

Sorry for the late reply. I have been very busy in the last days...
Is this VB.NET or VB6? You don't use Set in VB.NET. You also can't

It is VB6! And if I uncomment the following line in my connection
routine, the AddIn and Outlook closes fine:

Application.COMAddIns.Item("MyAddInName.Connect").Object =
ConnectClass

But if I do not use this line of code, I'm no longer able to call a
function in the AddIn from outside using code like in COMAddIns.Item
(xyz).Object.

Any idea how to release this connection (established with the line
above) to allow outlook to close?

Kukulkan
 
Oh, sorry.
It is VB6! And if I uncomment the following line in my connection
routine, the AddIn and Outlook closes fine:

Application.COMAddIns.Item("MyAddInName.Connect").Object =
ConnectClass

I mean if I *comment* this line (this line causes Outlook not to
close).

Kukulkan
 
If this is VB6 code then you aren't really following that KB article you
cited, although I think that article isn't very well written to begin with.
In the OnConnection() event handler all you need is a line like this to make
the hook-up for external usage:

AddInInst.Object = Me

You don't need anything else there at all.
 
Hi Ken,
In the OnConnection() event handler all you need is a line like this to make
the hook-up for external usage:

    AddInInst.Object = Me

You don't need anything else there at all.

Thank you very much. :-)

This guided me to the right way and now it works. I needed to wrap the
function from the connector to my ConnectClass but it works ok here.

Kukulkan
 
Back
Top