Microsoft KB Archive/171429: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "<" to "<")
m (Text replacement - "&" to "&")
 
(2 intermediate revisions by the same user not shown)
Line 67: Line 67:


   // TO DO: If you are using CDO (1.1) unremark the next line:
   // TO DO: If you are using CDO (1.1) unremark the next line:
   // #import <olemsg32.dll&gt; no_namespace
   // #import <olemsg32.dll> no_namespace


   // TO DO: If you are using CDO (1.2, 1.21) unremark the next line:
   // TO DO: If you are using CDO (1.2, 1.21) unremark the next line:
   // #import <cdo.dll&gt; no_namespace
   // #import <cdo.dll> no_namespace


   #import <olemsg32.dll&gt; no_namespace
   #import <olemsg32.dll> no_namespace


   #include <assert.h&gt;
   #include <assert.h>
   #include <stdio.h&gt;
   #include <stdio.h>
   #include <tchar.h&gt;
   #include <tchar.h>


   void dump_com_error(_com_error &amp;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());
       _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 103: Line 103:
           // Uncomment one of the next two lines of code as appropriate:
           // Uncomment one of the next two lines of code as appropriate:
           // Create a MAPI.Session pointer with CDO (1.1)
           // Create a MAPI.Session pointer with CDO (1.1)
           // SessionPtr pSession(&quot;MAPI.Session&quot;);
           // SessionPtr pSession("MAPI.Session");
           // or Create a MAPI.Session pointer with CDO (1.2, 1.21)
           // or Create a MAPI.Session pointer with CDO (1.2, 1.21)
           // _SessionPtr pSession(&quot;MAPI.Session&quot;);
           // _SessionPtr pSession("MAPI.Session");


           // Logon using the specified profile
           // Logon using the specified profile
           pSession-&gt;Logon(&quot;YourValidProfileNameHere&quot;);
           pSession->Logon("YourValidProfileNameHere");


           // Create pointer to the Inbox Folder
           // Create pointer to the Inbox Folder
           FolderPtr pFolder = pSession-&gt;Inbox;
           FolderPtr pFolder = pSession->Inbox;


           // Create pointer to the Messages Collection
           // Create pointer to the Messages Collection
           MessagesPtr pMessages = pFolder-&gt;Messages;
           MessagesPtr pMessages = pFolder->Messages;


           // Get the first Message object before filter is applied
           // Get the first Message object before filter is applied
           MessagePtr pAMessage = pMessages-&gt;GetFirst();
           MessagePtr pAMessage = pMessages->GetFirst();


           // Process contents of Folder
           // Process contents of Folder
Line 123: Line 123:
           {
           {
               // Display Properties
               // Display Properties
               MessageBoxW (NULL,pAMessage-&gt;Subject.bstrVal,NULL,MB_OK);
               MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK);


               // Get next Message
               // Get next Message
               pAMessage = NULL;
               pAMessage = NULL;
               pAMessage = pMessages-&gt;GetNext();
               pAMessage = pMessages->GetNext();
           }
           }


Line 137: Line 137:


           // Aquire pointer to the Inbox Folder
           // Aquire pointer to the Inbox Folder
           pFolder = pSession-&gt;Inbox;
           pFolder = pSession->Inbox;


           // Aquire pointer to the Messages Collection
           // Aquire pointer to the Messages Collection
           pMessages = pFolder-&gt;Messages;
           pMessages = pFolder->Messages;


           // Acquire pointer and set properties of the MessageFilter
           // Acquire pointer and set properties of the MessageFilter
           MessageFilterPtr pMsgFilt = pMessages-&gt;Filter;
           MessageFilterPtr pMsgFilt = pMessages->Filter;
           pMsgFilt-&gt;Unread = (bool)TRUE;
           pMsgFilt->Unread = (bool)TRUE;


           // Get the first Message object after filter is applied
           // Get the first Message object after filter is applied
           pAMessage = pMessages-&gt;GetFirst();
           pAMessage = pMessages->GetFirst();


           // Process contents of Folder
           // Process contents of Folder
Line 153: Line 153:
           {
           {
               // Display Properties
               // Display Properties
               MessageBoxW (NULL,pAMessage-&gt;Subject.bstrVal,NULL,MB_OK);
               MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK);


               // Get next Message
               // Get next Message
               pAMessage = NULL;
               pAMessage = NULL;
               pAMessage = pMessages-&gt;GetNext();
               pAMessage = pMessages->GetNext();
           }
           }


Line 169: Line 169:
           // GetFirst() without a filter in place
           // GetFirst() without a filter in place
           // Aquire pointer to the Inbox Folder
           // Aquire pointer to the Inbox Folder
           pFolder = pSession-&gt;Inbox;
           pFolder = pSession->Inbox;


           // Aquire pointer to the Messages Collection
           // Aquire pointer to the Messages Collection
           pMessages = pFolder-&gt;Messages;
           pMessages = pFolder->Messages;


           // Get the first Message object after filter is unapplied
           // Get the first Message object after filter is unapplied
           pAMessage = pMessages-&gt;GetFirst();
           pAMessage = pMessages->GetFirst();


           // Process contents of Folder
           // Process contents of Folder
Line 181: Line 181:
           {
           {
               // Display Properties
               // Display Properties
               MessageBoxW (NULL,pAMessage-&gt;Subject.bstrVal,NULL,MB_OK);
               MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK);


               // Get next Message
               // Get next Message
               pAMessage = NULL;
               pAMessage = NULL;
               pAMessage = pMessages-&gt;GetNext();
               pAMessage = pMessages->GetNext();
           }
           }


           // Logoff of the MAPI Session
           // Logoff of the MAPI Session
           pSession-&gt;Logoff();
           pSession->Logoff();
       }
       }
       catch (_com_error &amp;e)
       catch (_com_error &e)
       {
       {
           dump_com_error(e);
           dump_com_error(e);

Latest revision as of 12:30, 21 July 2020

Knowledge Base


Article ID: 171429

Article Last Modified on 5/9/2005



APPLIES TO

  • Microsoft Collaboration Data Objects 1.1
  • Microsoft Collaboration Data Objects 1.2
  • Microsoft Collaboration Data Objects 1.21



This article was previously published under Q171429

SUMMARY

Changes to the CDO (1.1, 1.2, 1.21) MessageFilter properties appear to have no effect.

MORE INFORMATION

The following code sample shows how to activate, then deactivate a CDO (1.1, 1.2, 1.21) MessageFilter via Visual C++.

The key to successfully shutting or altering the MessageFilter is to be sure to destroy any reference that is made to any object related to the MessageFilter (also known as Folder:MessagesCollection:MessageFilter).

Code Sample:

   /**********************************************************/ 
   // MSGFILTER.CPP
   // -------------
   // This program demonstrates how the CDO (1.1, 1.2, 1.21)
   // MessageFilter works via VC++. This sample requires VC++
   // version 5.0 or higher.
   /**********************************************************/ 

   // TO DO: If you are using CDO (1.1) unremark the next line:
   // #import <olemsg32.dll> no_namespace

   // TO DO: If you are using CDO (1.2, 1.21) unremark the next line:
   // #import <cdo.dll> no_namespace

   #import <olemsg32.dll> no_namespace

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

   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());
       _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);
    }

   // If this is placed in the scope of the smart pointers, they must be
   // explicitly Release(d) before CoUninitialize() is called.  If any
   // reference count is non-zero, a protection fault will occur.
   struct StartOle {
      StartOle() { CoInitialize(NULL); }
      ~StartOle() { CoUninitialize(); }
   } _inst_StartOle;

   void main()
   {
   try
      {
          // Uncomment one of the next two lines of code as appropriate:
          // Create a MAPI.Session pointer with CDO (1.1)
          // SessionPtr pSession("MAPI.Session");
          // or Create a MAPI.Session pointer with CDO (1.2, 1.21)
          // _SessionPtr pSession("MAPI.Session");

          // Logon using the specified profile
          pSession->Logon("YourValidProfileNameHere");

          // Create pointer to the Inbox Folder
          FolderPtr pFolder = pSession->Inbox;

          // Create pointer to the Messages Collection
          MessagesPtr pMessages = pFolder->Messages;

          // Get the first Message object before filter is applied
          MessagePtr pAMessage = pMessages->GetFirst();

          // Process contents of Folder
          while (pAMessage != NULL)
          {
              // Display Properties
              MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK);

              // Get next Message
              pAMessage = NULL;
              pAMessage = pMessages->GetNext();
          }

          // Destroy the reference to the to the Inbox, Messages
          // Collection, and Message then reaquire them
          pFolder = NULL;
          pMessages = NULL;
          pAMessage = NULL;

          // Aquire pointer to the Inbox Folder
          pFolder = pSession->Inbox;

          // Aquire pointer to the Messages Collection
          pMessages = pFolder->Messages;

          // Acquire pointer and set properties of the MessageFilter
          MessageFilterPtr pMsgFilt = pMessages->Filter;
          pMsgFilt->Unread = (bool)TRUE;

          // Get the first Message object after filter is applied
          pAMessage = pMessages->GetFirst();

          // Process contents of Folder
          while (pAMessage != NULL)
          {
              // Display Properties
              MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK);

              // Get next Message
              pAMessage = NULL;
              pAMessage = pMessages->GetNext();
          }

          // Destroy the reference to the Inbox, Messages Collection,
          // MessageFilter, and Message then reaquire them
          pFolder = NULL;
          pMessages = NULL;
          pMsgFilt = NULL;
          pAMessage = NULL;

          // GetFirst() without a filter in place
          // Aquire pointer to the Inbox Folder
          pFolder = pSession->Inbox;

          // Aquire pointer to the Messages Collection
          pMessages = pFolder->Messages;

          // Get the first Message object after filter is unapplied
          pAMessage = pMessages->GetFirst();

          // Process contents of Folder
          while (pAMessage != NULL)
          {
              // Display Properties
              MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK);

              // Get next Message
              pAMessage = NULL;
              pAMessage = pMessages->GetNext();
          }

          // Logoff of the MAPI Session
          pSession->Logoff();
      }
      catch (_com_error &e)
      {
          dump_com_error(e);
      }
   }
                

Keywords: kbhowto kbmsg kbcode KB171429