PocketPC, Outlook and AddinMon

S

Sanjay Singh

Problem:
User has Outlook open and Pocket PC connected (via Active Sync). My addin
shows up and works fine.

User then closes Outlook (Explorer) but Outlook remains running in the
background due to ActiveSync.

Use clicks the Outlook button so that a Explorer opens again.

Buttons for my addins no longer show up!

I know why this happens:
When the last Explorer was closed, my addin closed all its objects.
When the explorer is opened again, the Connection event does not fire again.

Solution?
I researched the newsgroups. AddinMon was initially recomended as a solution
to this kind of problem.

However newer postings seems to indicate that Ken (and the other experts) no
longer recommend this because of problems.

Is there any solution to this now that works without creating more problems?

Any help will be greatly appreciated.

Thanks
Sanjay
 
K

Ken Slovak - [MVP - Outlook]

Something like this would work, as the code in your designer class:

Implements IDTExtensibility2

Private gBaseClass As New clsAddin

'reference to trusted Application object
Private mobjOutlook As Outlook.Application

Private mblnTeardown As Boolean

'Event-aware references to Explorers collection & ActiveExplorer
Private WithEvents mcolExplorers As Outlook.Explorers
Private WithEvents molExplorer As Outlook.Explorer

Private WithEvents m_oTimer As CTimer

Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
'
On Error Resume Next
End Sub

Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
'
On Error Resume Next

If mblnTeardown = False Then
TearDown
End If
End Sub

Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)

On Error Resume Next

'set module level reference to COMAddIn object
Set mobjOutlook = Application

'event-aware reference to Explorers collection
'use NewExplorer event to watch for UI creation
Set mcolExplorers = mobjOutlook.Explorers

'put ProgID in a global variable
gstrProgID = AddInInst.ProgId

AddInInst.Object = Me

mblnTeardown = False

'Are we starting with UI?
If mcolExplorers.Count > 0 Then
g_blnFirstTimer = True

Set molExplorer = mobjOutlook.Explorers.Item(1)

'we have UI - initialize base class
gBaseClass.InitHandler mobjOutlook, AddInInst.ProgId
Else
'do nothing
'monitor Explorers collection (in this module)
'if NewExplorer event is raised then we have UI
End If
End Sub

Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
'Tear down the class
'IMPORTANT: This event will not fire when
'RemoveMode = ext_dm_HostShutdown
'It will fire when RemoveMode = ext_dm_UserClosed

On Error Resume Next

If mblnTeardown = False Then
TearDown

End If
End Sub

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
'

On Error Resume Next
End Sub

' Release object references and remove message hook
Private Sub TearDown()
On Error Resume Next

mblnTeardown = True

'Tear down the base class
If gBaseClass.Init = True Then
gBaseClass.UnInitHandler
DoEvents
End If
Set gBaseClass = Nothing

'release reference to Outlook objects
Set molExplorer = Nothing
Set mcolExplorers = Nothing
Set mobjOutlook = Nothing
End Sub

' NewExplorer event will be raised if there is UI
Private Sub mcolExplorers_NewExplorer(ByVal Explorer As Outlook.Explorer)
On Error Resume Next

'assign ActiveExplorer
Set molExplorer = Explorer

If gBaseClass.Init = False Then
'we didn't have UI before - initialize add-in objects
gBaseClass.InitHandler mobjOutlook, gstrProgID
End If
End Sub

' Monitor Explorer_Close to see when UI "disappears"
Private Sub molExplorer_Close()
On Error Resume Next

'release current reference
Set molExplorer = Nothing

Set molExplorer = mobjOutlook.ActiveExplorer
If (molExplorer Is Nothing) And (mobjOutlook.Inspectors.Count = 0) Then
'release add-in objects
gBaseClass.UnInitHandler
End If
End Sub
 
S

Sanjay Singh

Thanks Ken. I will try that out.

I noticed that there is also a CTimer object declared in you sample code but
I do not see it used anywhere.

Do we need it for anything specific?

Thanks
Sanjay
 
K

Ken Slovak - [MVP - Outlook]

I took that code from one of my addins that uses the addinmon replacement we
developed. I used the CTimer for timing a process in my code and forgot to
remove its declaration.
 
S

Sanjay Singh

Thanks Ken.

Was AddinMon (and its replacement code) only needed for a specific version
of Outlook 2002.

I have not implemented it in my addin but have not had complaints.

Do I need to do something about it. I would rather deal with the problem
before someone complains about it.

I am using Outlook 2003 with Active Sync and a Pocket PC. Are there certain
steps I can take to duplicate the problem on my computer.

As always, thank you for your fantastic help.

Sanjay
 
K

Ken Slovak - [MVP - Outlook]

AddInMon was originally implemented by Randy Byrne and David Kane of
MicroEye for Outlook 2000. I worked on that and was involved with later
revisions to AddInMon.

Due to various changes in Outlook since Outlook 2000 and how things like PDA
synch software are implemented it became impossible to maintain AddInMon,
and it was a hack. It's a separate EXE and we didn't like a lot of things
about it. So David Kane and I wrote the new replacement that I showed.

I've used the new version for everything from Outlook 2000 to 2007, and I've
implemented versions of it for VB.NET and C# also.
 
S

Sanjay Singh

Do I need to know about the timer part to implement the addinmon
replacement.

If so, is sample code for this available.

Thanks
Sanjay
 
S

Sanjay Singh

Do we need to put similar code to catch the last Inpsector as well?

I currently have code that does this in the base Outlook addin class.

Should that now be shifted here?

Thanks
Sanjay
 
K

Ken Slovak - [MVP - Outlook]

No, as I mentioned that timer was for something else. Just remove the
declaration.
 
K

Ken Slovak - [MVP - Outlook]

If you're using an Inspector wrapper you can place this in the designer
class:

'Event-aware references to Inspectors collection & ActiveInspector
Private WithEvents mcolInspectors As Outlook.Inspectors
Private WithEvents molInspector As Outlook.Inspector

'In OnConnection
Set mcolInspectors = mobjOutlook.Inspectors

Private Sub mcolInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)
On Error Resume Next

'assign ActiveInspector
Set molInspector = Inspector

If gBaseClass.Init = False Then
'we didn't have UI before - initialize add-in objects
Debug.Print "init for gbaseclass, NewInspector"
gBaseClass.InitHandler mobjOutlook, gstrProgID
End If
End Sub

Private Sub molInspector_Close()
On Error Resume Next

'release current reference
Set molInspector = Nothing

Set molInspector = mobjOutlook.ActiveInspector
If (mobjOutlook.Explorers.Count = 0) And (mobjOutlook.Inspectors.Count <=
1) Then
TearDown 'allows OnDisconnection to fire, thereby allowing the next open
to reset us.
End If
End Sub
 
S

Sanjay Singh

Shouldn't we be doing a gBaseClass.UnInitHandler instead of a TearDown in
the Inspector_Close event.

Sanjay
 
K

Ken Slovak - [MVP - Outlook]

In the code I use most or all of my uninithandler code is now in Teardown.
 

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