Article ID: 262809 - Last Review: October 28, 2006 - Revision: 2.3

INFO: Create/Send Recurring Meeting Request With Exception

This article was previously published under Q262809

On This Page

SUMMARY

This article contains a Microsoft Visual C++ code sample that uses Collaboration Data Objects (CDO) for Exchange 2000 library, Active Directory Objects (ADO) library, and Active Directory Services Interface (ADSI) to demonstrate the following functionalities:
  • How to create a recurring appointment.
  • How to add an exception to a recurring appointment.
  • How to create a meeting request and send it.

MORE INFORMATION

The code sample in the article needs to be linked with the following libraries:
  • Activeds.lib
  • Adsiid.lib
To run the code, search for the "TODO" string, to change the meeting organizer's and attendee's mailbox names.

The Sample Code

// Link to activeds.lib adsiid.lib 
#import <msado15.dll> no_namespace 
#import <cdoex.dll> rename_namespace("CDO") raw_interfaces_only
#include <activeds.h> 
#include <stdio.h> 
#include <tchar.h> 
enum CdoFrequency 
{ 
cdoSecondly = 1, 
cdoMinutely = 2, 
cdoHourly = 3, 
cdoDaily = 4, 
cdoWeekly = 5, 
cdoMonthly = 6, 
cdoYearly = 7, 
}; 
enum CdoAttendeeRoleValues 
{
cdoRequiredParticipant = 0,
cdoOptionalParticipant = 1,
cdoNonParticipant = 2,
cdoChair = 3
}; 
HRESULT GetDomainName(BSTR * bstrDomainName); 
HRESULT SendMeetingRequest(BSTR bstrDomainName, BSTR bstrUser, BSTR bstrRecipient);

struct StartOle { 
StartOle() { CoInitialize(NULL); } 
~StartOle() { CoUninitialize(); } 
} _inst_StartOle; 

void main() 
{ 
HRESULT hr = S_OK; 
BSTR bstrDomainDNSName; 
// Get Domain Name 
hr = GetDomainName(&bstrDomainDNSName); 

// Create and send a recurring meeting request to a user
// TODO: change the second parameter to your mailbox name (meeting organizer)
// TODO: change the third parameter to the recipient's e-mail address or mailbox name
hr = SendMeetingRequest(bstrDomainDNSName, L"User1", L"User2"); 
} 

////////////////////////////////////////////////////////////////////////////////////////////////// 
// SendMeetingRequest 
// 
// Params: [in] BSTR bstrDomainName Domain DNS Name 
// [in] BSTR bstrUser Meeting organizer's mailbox name 
// [in] BSTR bstrRecipient Recipient's mailbox name
// 
// Output: HRESULT 
// Purpose: To demonstrate; 1.How to create a recurring appointment
// 2.How to add an exception to a recurring appointment
// 3.How to create a meeting request and send it 
///////////////////////////////////////////////////////////////////////////////////////////////// 
HRESULT SendMeetingRequest(BSTR bstrDomainName, BSTR bstrUser, BSTR bstrRecipient) 
{ 
HRESULT hr = S_OK; 

_bstr_t szCalendarURL ="file://./backofficestorage/" + (_bstr_t)bstrDomainName + "/MBX/" + (_bstr_t)bstrUser + "/Calendar"; 

try{ 
CDO::IMessagePtr pMsg(_uuidof(CDO::Message));
CDO::IAppointmentPtr pAppt(_uuidof(CDO::Appointment));
CDO::IRecurrencePatternsPtr pRecPatterns;
CDO::IRecurrencePatternPtr pRecPattern;
CDO::IDataSourcePtr pDataSrc; 
CDO::IAttendeesPtr pAttendees;
CDO::IAttendeePtr pAttendee;
CDO::IExceptionsPtr pExceptions;
CDO::IExceptionPtr pException;
CDO::ICalendarMessagePtr pCalendarMessage;

SYSTEMTIME st = {0}; 
SYSTEMTIME et = {0};

DATE dst, det; 

// Specify the StartTime and EndTime values.
st.wYear = 2000; 
st.wMonth = 2; 
st.wDay = 1; 
st.wHour = 13; 
st.wMinute = 30; 
et.wYear = 2000; 
et.wMonth = 2; 
et.wDay = 1; 
et.wHour = 16; 
et.wMinute = 30; 

// Convert System value to double DATE 
SystemTimeToVariantTime(&st, &dst); 
SystemTimeToVariantTime(&et, &det); 
// Set Appointment's properties. 
pAppt->put_Subject(L"Exchange Server 2000 Training."); 
pAppt->put_Location(L"Conference Room 444"); 
pAppt->put_TextBody(L"Please bring the course notes."); 
pAppt->put_StartTime(dst); 
pAppt->put_EndTime(det); 

// Invite an Attendee.
pAppt->get_Attendees(&pAttendees);
pAttendees->Add(bstrRecipient, &pAttendee);
pAttendee->put_Role((enum CDO::CdoAttendeeRoleValues)cdoRequiredParticipant);

// Create a Recurrence Pattern.
// Set the RecurrencePattern properties to make the Appointment a bi-weekly Appointment.
pAppt->get_RecurrencePatterns(&pRecPatterns);
pRecPatterns->Add(L"ADD", &pRecPattern);
pRecPattern->put_Frequency((enum CDO::CdoFrequency)cdoWeekly); 
pRecPattern->put_Interval(2); // every 2 weeks
pRecPattern->put_Instances(5); // end after 5 instances

// Create an Exception to the Appointment.
pAppt->get_Exceptions(&pExceptions);

// Delete the second instance from the series.
pExceptions->Add(L"DELETE", &pException);

// Specify the start time of the second Appointment in the series.
 st.wYear = 2000; 
 st.wMonth = 2; 
 st.wDay = 15; 
 st.wHour = 13; 
 st.wMinute = 30;
 
 SystemTimeToVariantTime(&st, &dst); 
   
 // dst is the StartTime of the second instance
 pException->put_RecurrenceID(dst);
   
// Create a CalendarMessage 
pAppt->CreateRequest(&pCalendarMessage);
pCalendarMessage->get_Message(&pMsg);

// Get the data source to save the Meeting into organizer's calendar.
pAppt->get_DataSource(&pDataSrc);

// Send the Meeting Request
hr = pMsg->Send();
if (SUCCEEDED(hr)) 
_tprintf(_T("Recurring meeting request is sent.\n")); 

// Optional : You can save the meeting into organizer's calendar. 
hr = pDataSrc->SaveToContainer(szCalendarURL, 
0, 
adModeReadWrite, 
adCreateOverwrite, 
adOpenSource, 
L"", 
L""); 
if (SUCCEEDED(hr)) 
_tprintf(_T("The meeting is saved to the organizer's calendar.\n")); 


}
catch(_com_error &e) 
{ 

printf("HResult = %x\n", e.Error()); 
printf("%S\n", e.Description()); 

} 
return hr;

} 

////////////////////////////////////////////////////////////////////////////////////////////////// 
// GetDomainName 
// 
// Params: [out] BSTR * bstrDomainName 
// Output: HRESULT 
// Purpose: Retrieve the Domain DNS name. 
///////////////////////////////////////////////////////////////////////////////////////////////// 
HRESULT GetDomainName(BSTR * bstrDomainName) 
{ 
HRESULT hr = S_OK; 
IADsADSystemInfo *pADsys; 
hr = CoCreateInstance(CLSID_ADSystemInfo, 
NULL, 
CLSCTX_INPROC_SERVER, 
IID_IADsADSystemInfo, 
(void**)&pADsys); 
hr = pADsys->get_DomainDNSName(bstrDomainName); 

if (pADsys) 
pADsys->Release(); 
return hr; 
} 
				

Expected Results

  • The code will create the following four appointments in the organizer's calendar:
    February 1st, 2000 between 13:30 - 16:30
    February 29th, 2000 between 13:30 - 16:30
    March 14th, 2000 between 13:30 - 16:30
    March 29th, 2000 between 13:30 - 16:30
  • The code may then create a meeting request and send it to the attendee.

Keywords: 
kbinfo kbmsg KB262809
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Note: This article is from Microsoft Knowledage Base


How we have helped PC users like you

In the News: Read More In ...

Related problems posted by other users

more...