Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using VFPCOM to bind to Outlook events (ItemSend for example
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Using VFPCOM to bind to Outlook events (ItemSend for example
Miscellaneous
Thread ID:
00363457
Message ID:
00363457
Views:
105
Hi Folks,

I'm using VFPCOM to bind to the Outlook Application's ItemSend() event and keep getting a C0000005 error in VFP when I click the Send button in the outlook mail item.

Relevant code is as follows:

In the application object's init:
if USE_OUTLOOKINTERFACE and iscomobject('VFPCOM.COMUTIL') and iscomobject('outlook.application')
  this.oVFPCOM = create('VFPCOM.COMUTIL')
  this.oOutlook = createobject('outlook.application')
  this.oOutlookEventHandler = createobject('OutlookApplicationEvents')

  local lcError
  lcError = this.oVFPCOM.BindEvents(this.oOutlook, this.oOutlookEventHandler)
	
  if empty(lcError)
    this.lUseOutlookInterface = .t.
  else
    this.lUseOutlookInterface = .f.
  endif

else

  this.lUseOutlookInterface = .f.
endif
In the application object's SendEmail event:
with this

  local loMessage

  loMessage = .oOutlook.createitem(olMailItem)
  
  loMessage.UserProperties.Add('ToContactID', olNumber)
  loMessage.UserProperties.Add('FromRep', olText)
  loMessage.UserProperties('ToContactID') = this.GetCurrentContact()
  loMessage.UserProperties('FromRep') = this.cInitials

  loMessage.Recipients.Add(contactview.email)
  loMessage.Recipients.ResolveAll()
  loMessage.Display(.f.)

endwith
All goes well so far, the mail item is displayed (in the background and without the recipient filled in, but I'll get to that next). Hitting the send button in the mail item causes a C0000005 error in VFP.EXE.

The relevant class code for the OutlookApplicationEvents class is:
DEFINE CLASS OutlookApplicationEvents AS custom

PROCEDURE ItemSend(Item,Cancel)

* got as far as here once (and then didn't C5!)
if version(2) > 0
  set step on
endif

* if the item is a mail item and it has custom properties ToContactID and FromRep, make a note of its contents in the contact log
if vartype(Item.UserProperties('ToContactID')) = 'N' and vartype(Item.UserProperties('FromRep')) = 'C'

  local lcAttachments
  lcAttachments = ''
  for i = 1 to Item.Attachments.Count
      lcAttachments = lcAttachments + CR + Item.Attachments(i).DisplayName
  endfor

  goApp.MakeNote( ;
    'E', ;
    Item.UserProperties('ToContactID'), ;
    'Subject: ' + item.Subject + CR + 'To: ' + item.To + CR + '----' + CR + item.Body + CR + '-Attachments--' + lcAttachments, ;
    .t., ;
    .f., ;
    .f., ;
    .f., ;
    .t. ;
  )
endif

ENDPROC

[snipped the remaining code (defaults only)]
* I've tried both settings of _VFP.AutoYield.
* VFP6 SP3
* Outlook 2000
* Windows 2000

Any hints would be greatly appreciated.

Cheers,

Andrew


If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?


From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."


All my FoxTalk and other articles are available on my web site.


Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.
Next
Reply
Map
View

Click here to load this message in the networking platform