Microsoft KB Archive/262809

= INFO: Create/Send Recurring Meeting Request With Exception =

Article ID: 262809

Article Last Modified on 10/28/2006

-

APPLIES TO


 * Collaboration Data Objects for Exchange 2000
 * Microsoft Active Directory Service Interfaces 2.5

-



This article was previously published under Q262809





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 &quot;TODO&quot; string, to change the meeting organizer's and attendee's mailbox names.

The Sample Code
// Link to activeds.lib adsiid.lib 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);
 * 1) import  no_namespace
 * 2) import  rename_namespace(&quot;CDO&quot;) raw_interfaces_only
 * 3) include 
 * 4) include 
 * 5) include 

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&quot;User1&quot;, L&quot;User2&quot;); }

////////////////////////////////////////////////////////////////////////////////////////////////// // 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 =&quot;file://./backofficestorage/&quot; + (_bstr_t)bstrDomainName + &quot;/MBX/&quot; + (_bstr_t)bstrUser + &quot;/Calendar&quot;;

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&quot;Exchange Server 2000 Training.&quot;); pAppt->put_Location(L&quot;Conference Room 444&quot;); pAppt->put_TextBody(L&quot;Please bring the course notes.&quot;); 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&quot;ADD&quot;, &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&quot;DELETE&quot;, &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(&quot;Recurring meeting request is sent.\n&quot;));

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

} catch(_com_error &e) {

printf(&quot;HResult = %x\n&quot;, e.Error); printf(&quot;%S\n&quot;, 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

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.