Can not cast from type System.__ComObject to type Outlook.ApplicationClass an new Outlook.Applicatio

  • Thread starter Thread starter Me
  • Start date Start date
M

Me

This is my problem,

Using some code from Paul Reynolds I found at www.ftponline.com (VSM
Archives) i'm trying to make a program interact with different versions of
outlook. Right now i'm only testing on a outlook 2002 version but the
following occurs.

The detetcion of the installed version of outlook works fine. But when a
version of it is beeing inisialized (new Outlook.ApplicaionClass) I get the
following error:
Unable to cast object of type System.__ComObject to type
Outlook.ApplicationClass

Here is a snapshot of the code:

Private m_olApp As Outlook.ApplicationClass = Nothing

Private m_olNS As Outlook.NameSpace = Nothing

Private m_olExplorers As Outlook.Explorers = Nothing

Private m_olInspectors As Outlook.Inspectors = Nothing

Private m_olExplorer As Outlook.ExplorerClass = Nothing

Private m_olInspector As Outlook.InspectorClass = Nothing

Public Sub New()

MyBase.New()

End Sub

Public Overrides Sub InitOutlook()

m_olApp = New Outlook.ApplicationClass 'Create the outlook app window <=
THE ERROR OCCURS HERE

m_olNS = m_olApp.GetNamespace(MAPI_NS) 'Get access to MAPI namespace

m_olNS.Logon(String.Empty, String.Empty, False, False) 'Use current outlook
session

'Get our line into the explorers and inspectors so that we can properly
detect shutdown

m_olExplorers = m_olApp.Explorers

m_olInspectors = m_olApp.Inspectors

'Type conversion required due to "ambiguous name" issue

m_olExplorer = CType(m_olApp.ActiveExplorer, Outlook.ExplorerClass)


The strange thing is... The first time a ran the sample programm it worked
fine. Now when i'm trying to run it "out of the box" it does not work
anymore. Any ideas what could cause this problem?

Thanks in advance for any help

Bart Seresia
 
Back
Top