Microsoft KB Archive/248349: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "&" to "&")
m (Text replacement - """ to """)
 
Line 58: Line 58:


#import <cdo.dll> no_namespace
#import <cdo.dll> no_namespace
#import &quot;c:\\Program Files\\Microsoft Office\\Office\\Addins\\esconf.dll&quot; no_namespace
#import "c:\\Program Files\\Microsoft Office\\Office\\Addins\\esconf.dll" no_namespace


struct StartOle {
struct StartOle {
Line 67: Line 67:
void dump_com_error(_com_error &e)
void dump_com_error(_com_error &e)
{
{
   _tprintf(_T(&quot;Oops - hit an error!\n&quot;));
   _tprintf(_T("Oops - hit an error!\n"));
   _tprintf(_T(&quot;\a\tCode = %08lx\n&quot;), e.Error());
   _tprintf(_T("\a\tCode = %08lx\n"), e.Error());
   _tprintf(_T(&quot;\a\tCode meaning = %s\n&quot;), e.ErrorMessage());
   _tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
   _tprintf(_T(&quot;\a\tWcode = %08lx\n&quot;), e.WCode());
   _tprintf(_T("\a\tWcode = %08lx\n"), e.WCode());
   _bstr_t bstrSource(e.Source());
   _bstr_t bstrSource(e.Source());
   _bstr_t bstrDescription(e.Description());
   _bstr_t bstrDescription(e.Description());
   _tprintf(_T(&quot;\a\tSource = %s\n&quot;), (LPCTSTR) bstrSource);
   _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
   _tprintf(_T(&quot;\a\tDescription = %s\n&quot;), (LPCTSTR) bstrDescription);
   _tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}
}


Line 81: Line 81:
     try {
     try {
         // Setup MAPI session
         // Setup MAPI session
         _SessionPtr pSession(&quot;MAPI.Session&quot;);
         _SessionPtr pSession("MAPI.Session");
         pSession->Logon(&quot;YourProfileName&quot;);
         pSession->Logon("YourProfileName");


         // Setup Events object
         // Setup Events object
         IEventsPtr pEvents(&quot;MSExchange.Events&quot;);
         IEventsPtr pEvents("MSExchange.Events");
         pEvents->put_Session(pSession->GetMAPIOBJECT());
         pEvents->put_Session(pSession->GetMAPIOBJECT());


Line 97: Line 97:
         // Create new event binding  
         // Create new event binding  
         IEventBindingPtr pBinding(pBindings->Add());
         IEventBindingPtr pBinding(pBindings->Add());
         _bstr_t bstrName(&quot;TestBinding&quot;);
         _bstr_t bstrName("TestBinding");
      
      
         pBinding->PutName(bstrName);
         pBinding->PutName(bstrName);
Line 112: Line 112:
         // standard Event Scripting Agent, if you are using a custom
         // standard Event Scripting Agent, if you are using a custom
         // event handler, you should specify it's class ID here instead.
         // event handler, you should specify it's class ID here instead.
         pBinding->PutHandlerClassID(&quot;{69E54151-B371-11D0-BCD9-00AA00C1AB1C}&quot;);
         pBinding->PutHandlerClassID("{69E54151-B371-11D0-BCD9-00AA00C1AB1C}");


         ISchedulePtr pSchedule(pBinding->GetSchedule());
         ISchedulePtr pSchedule(pBinding->GetSchedule());
Line 126: Line 126:
         pBoundFolder->SaveChanges();
         pBoundFolder->SaveChanges();


         _tprintf(&quot;TestBinding installed\n&quot;);
         _tprintf("TestBinding installed\n");
          
          
         pSession->Logoff();   
         pSession->Logoff();   

Latest revision as of 13:50, 21 July 2020

Knowledge Base


Article ID: 248349

Article Last Modified on 6/29/2004



APPLIES TO

  • Microsoft Exchange Server 5.5 Standard Edition
  • Microsoft Collaboration Data Objects 1.21



This article was previously published under Q248349

SUMMARY

This article contains a Microsoft Visual C++ code sample that demonstrates how to bind an agent to an Inbox using Collaboration Data Objects (CDO) and ESCONF libraries. The article assumes that the Inbox folder is located on an Exchange Server 5.5 computer.

MORE INFORMATION

Sample Code

#include <stdio.h>
#include <tchar.h>

#import <cdo.dll> no_namespace
#import "c:\\Program Files\\Microsoft Office\\Office\\Addins\\esconf.dll" no_namespace

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

void dump_com_error(_com_error &e)
{
  _tprintf(_T("Oops - hit an error!\n"));
  _tprintf(_T("\a\tCode = %08lx\n"), e.Error());
  _tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
  _tprintf(_T("\a\tWcode = %08lx\n"), e.WCode());
  _bstr_t bstrSource(e.Source());
  _bstr_t bstrDescription(e.Description());
  _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
  _tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}

void main (void)
{
    try {
        // Setup MAPI session
        _SessionPtr pSession("MAPI.Session");
        pSession->Logon("YourProfileName");

        // Setup Events object
        IEventsPtr pEvents("MSExchange.Events");
        pEvents->put_Session(pSession->GetMAPIOBJECT());

        // Get pointer to Inbox
        _variant_t vInbox(pSession->GetInbox());

        // Get BoundFolder and associated Event Bindings
        IBoundFolderPtr pBoundFolder(pEvents->GetBoundFolder(&vInbox, true));
        IEventBindingsPtr pBindings(pBoundFolder->GetBindings());

        // Create new event binding 
        IEventBindingPtr pBinding(pBindings->Add());
        _bstr_t bstrName("TestBinding");
    
        pBinding->PutName(bstrName);
        pBinding->PutActive(true);
        // EventMask:   None = 0,
        //      ScheduledEvents = 1,
        //      NewItemEvents = 2,
        //      ChangedItemEvents = 4,
        //      DeletedItemEvents = 8,
        //      AllEvents = 65535 
        pBinding->PutEventMask(1); // ScheduledEvents

        // The following is the proper class ID for events based on the 
        // standard Event Scripting Agent, if you are using a custom
        // event handler, you should specify it's class ID here instead.
        pBinding->PutHandlerClassID("{69E54151-B371-11D0-BCD9-00AA00C1AB1C}");

        ISchedulePtr pSchedule(pBinding->GetSchedule());
        // ScheduleType: 
        //      ScheduleTypeUnknown = 0,
        //      ScheduleTypeHourly = 1,
        //      ScheduleTypeDaily = 2,
        //      ScheduleTypeWeekly = 3
        pSchedule->put_Type((long)1); //Hourly
        pSchedule->PutInterval((long)60); //60 minutes

        pBinding->SaveChanges();
        pBoundFolder->SaveChanges();

        _tprintf("TestBinding installed\n");
        
        pSession->Logoff();  
    }
    catch (_com_error &e)
    {
        dump_com_error(e);
    }
    return;
}
                

Please note that to bind an agent to Exchange Server Mailbox Folder, you must have at least Author permissions on the EventConfig_servername object in the Exchange Server directory.

REFERENCES

For more information on how to configure the appropriate permissions, please refer to the following Knowledge Base article:

180121 Agents Tab Is Missing from Folder Properties



Additional query words: Agent Bind CDO ESCONF

Keywords: kbhowto kbmsg KB248349