C
ChrisA
I have a WinForms app, written in VB.NET, with VS 2003, which opens an
Outlook 2003 (or 2002) "new message" form with the following code:
------------------------------------------------
' lines doing setup snipped
Me.WordDoc = Me.WordApp.Documents.Add(' blah blah
Me.OutgoingMailItem = CType(WordDoc.MailEnvelope.Item,
Outlook.MailItemClass)
' lines setting message properties snipped
AddHandler OutgoingMailItem.ItemEvents_Event_Send, AddressOf Me.HandleSend
AddHandler OutgoingMailItem.ItemEvents_Event_Close, AddressOf
Me.HandleWordAppClose
Me.WordApp.Visible = True
-------------------------------------------------
This works fine with 1.1 and VS 2003. I can catch the "Send" event and the
message ends up in the Sent Items folder.
However, having imported the whole solution to VS 2005, I get a run time
error on
Me.OutgoingMailItem = CType(WordDoc.MailEnvelope.Item,
Outlook.MailItemClass)
The text of the error message is:
"Unable to cast COM object of type 'System.__ComObject' to class type
'Outlook.MailItemClass'. COM components that enter the CLR and do not
support IProvideClassInfo or that do not have any interop assembly
registered will be wrapped in the __ComObject type. Instances of this type
cannot be cast to any other class; however they can be cast to interfaces as
long as the underlying COM component supports QueryInterface calls for the
IID of the interface."
If instead I cast the OutgoingMailItem to the "Outlook.MailItem" interface
type (instead of MailItemClass), the ItemEvents_Event_Send and
ItemEvents_Event_Close events seem not
to be available, so I can't catch the send (or the close - I need both).
Any suggestions or workarounds gratefully received.
ChrisA
Outlook 2003 (or 2002) "new message" form with the following code:
------------------------------------------------
' lines doing setup snipped
Me.WordDoc = Me.WordApp.Documents.Add(' blah blah
Me.OutgoingMailItem = CType(WordDoc.MailEnvelope.Item,
Outlook.MailItemClass)
' lines setting message properties snipped
AddHandler OutgoingMailItem.ItemEvents_Event_Send, AddressOf Me.HandleSend
AddHandler OutgoingMailItem.ItemEvents_Event_Close, AddressOf
Me.HandleWordAppClose
Me.WordApp.Visible = True
-------------------------------------------------
This works fine with 1.1 and VS 2003. I can catch the "Send" event and the
message ends up in the Sent Items folder.
However, having imported the whole solution to VS 2005, I get a run time
error on
Me.OutgoingMailItem = CType(WordDoc.MailEnvelope.Item,
Outlook.MailItemClass)
The text of the error message is:
"Unable to cast COM object of type 'System.__ComObject' to class type
'Outlook.MailItemClass'. COM components that enter the CLR and do not
support IProvideClassInfo or that do not have any interop assembly
registered will be wrapped in the __ComObject type. Instances of this type
cannot be cast to any other class; however they can be cast to interfaces as
long as the underlying COM component supports QueryInterface calls for the
IID of the interface."
If instead I cast the OutgoingMailItem to the "Outlook.MailItem" interface
type (instead of MailItemClass), the ItemEvents_Event_Send and
ItemEvents_Event_Close events seem not
to be available, so I can't catch the send (or the close - I need both).
Any suggestions or workarounds gratefully received.
ChrisA