J
John
Greetings,
I hope someone here can help me out with a couple of my questions.
The basic idea is to be able to create an appointment in Outlook (or
Exchange).
My boss's boss (i.e. the owner) has already told sales that we will
have this capability, so there are a number of people looking over my
shoulder here (although unobtrusively). I'm obviously not a C++
programmer by trade, and I actually don't need the program to be in
C++, but we don't have VB or DS.NET (yet) and I just need a working
prototype to wow the prospects for now. I got this code off the
internet.
Here are my questions, if anybody can help me out:
How can I get this program to compile and run?
How can I provide output (to a file would be fine)?
Should I be running this on the client or the server?
I'm using VC++ 5.0.
The problem I'm having right now is that Windows keeps getting
confused about whether it's a DOS program or not, so getting past that
hurdle will be crucial. Right now I try to run it (Command window or
just double click) I get the message "This program cannot be run in
DOS mode". If I create a shortcut for it, it's an MS Dos shortcut.
Here is my code:
#include <iads.h>
#include <adshlp.h>
#include <activeds.h>
#include <stdio.h>
#include <tchar.h>
#import <msado15.dll> no_namespace raw_interfaces_only
#import <cdoex.dll> rename_namespace("CDO") raw_interfaces_only
#import <cdosys.dll> no_namespace raw_interfaces_only
#include "class1.h"
#include <cdosysstr.h>
#include <cdosyserr.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
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);
//printf("1");
// 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"JohnS", L"JohnD");
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
}
I hope someone here can help me out with a couple of my questions.
The basic idea is to be able to create an appointment in Outlook (or
Exchange).
My boss's boss (i.e. the owner) has already told sales that we will
have this capability, so there are a number of people looking over my
shoulder here (although unobtrusively). I'm obviously not a C++
programmer by trade, and I actually don't need the program to be in
C++, but we don't have VB or DS.NET (yet) and I just need a working
prototype to wow the prospects for now. I got this code off the
internet.
Here are my questions, if anybody can help me out:
How can I get this program to compile and run?
How can I provide output (to a file would be fine)?
Should I be running this on the client or the server?
I'm using VC++ 5.0.
The problem I'm having right now is that Windows keeps getting
confused about whether it's a DOS program or not, so getting past that
hurdle will be crucial. Right now I try to run it (Command window or
just double click) I get the message "This program cannot be run in
DOS mode". If I create a shortcut for it, it's an MS Dos shortcut.
Here is my code:
#include <iads.h>
#include <adshlp.h>
#include <activeds.h>
#include <stdio.h>
#include <tchar.h>
#import <msado15.dll> no_namespace raw_interfaces_only
#import <cdoex.dll> rename_namespace("CDO") raw_interfaces_only
#import <cdosys.dll> no_namespace raw_interfaces_only
#include "class1.h"
#include <cdosysstr.h>
#include <cdosyserr.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
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);
//printf("1");
// 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"JohnS", L"JohnD");
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
}