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 | // #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 | // #import <cdo.dll> no_namespace | ||
#import <olemsg32.dll | #import <olemsg32.dll> no_namespace | ||
#include <assert.h | #include <assert.h> | ||
#include <stdio.h | #include <stdio.h> | ||
#include <tchar.h | #include <tchar.h> | ||
void dump_com_error(_com_error & | void dump_com_error(_com_error &e) | ||
{ | { | ||
_tprintf(_T( | _tprintf(_T("Oops - hit an error!\n")); | ||
_tprintf(_T( | _tprintf(_T("\a\tCode = %08lx\n"), e.Error()); | ||
_tprintf(_T( | _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( | _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource); | ||
_tprintf(_T( | _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( | // 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( | // _SessionPtr pSession("MAPI.Session"); | ||
// Logon using the specified profile | // Logon using the specified profile | ||
pSession- | pSession->Logon("YourValidProfileNameHere"); | ||
// Create pointer to the Inbox Folder | // Create pointer to the Inbox Folder | ||
FolderPtr pFolder = pSession- | FolderPtr pFolder = pSession->Inbox; | ||
// Create pointer to the Messages Collection | // Create pointer to the Messages Collection | ||
MessagesPtr pMessages = pFolder- | 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- | MessagePtr pAMessage = pMessages->GetFirst(); | ||
// Process contents of Folder | // Process contents of Folder | ||
Line 123: | Line 123: | ||
{ | { | ||
// Display Properties | // Display Properties | ||
MessageBoxW (NULL,pAMessage- | MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK); | ||
// Get next Message | // Get next Message | ||
pAMessage = NULL; | pAMessage = NULL; | ||
pAMessage = pMessages- | pAMessage = pMessages->GetNext(); | ||
} | } | ||
Line 137: | Line 137: | ||
// Aquire pointer to the Inbox Folder | // Aquire pointer to the Inbox Folder | ||
pFolder = pSession- | pFolder = pSession->Inbox; | ||
// Aquire pointer to the Messages Collection | // Aquire pointer to the Messages Collection | ||
pMessages = pFolder- | pMessages = pFolder->Messages; | ||
// Acquire pointer and set properties of the MessageFilter | // Acquire pointer and set properties of the MessageFilter | ||
MessageFilterPtr pMsgFilt = pMessages- | MessageFilterPtr pMsgFilt = pMessages->Filter; | ||
pMsgFilt- | pMsgFilt->Unread = (bool)TRUE; | ||
// Get the first Message object after filter is applied | // Get the first Message object after filter is applied | ||
pAMessage = pMessages- | pAMessage = pMessages->GetFirst(); | ||
// Process contents of Folder | // Process contents of Folder | ||
Line 153: | Line 153: | ||
{ | { | ||
// Display Properties | // Display Properties | ||
MessageBoxW (NULL,pAMessage- | MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK); | ||
// Get next Message | // Get next Message | ||
pAMessage = NULL; | pAMessage = NULL; | ||
pAMessage = pMessages- | 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- | pFolder = pSession->Inbox; | ||
// Aquire pointer to the Messages Collection | // Aquire pointer to the Messages Collection | ||
pMessages = pFolder- | pMessages = pFolder->Messages; | ||
// Get the first Message object after filter is unapplied | // Get the first Message object after filter is unapplied | ||
pAMessage = pMessages- | pAMessage = pMessages->GetFirst(); | ||
// Process contents of Folder | // Process contents of Folder | ||
Line 181: | Line 181: | ||
{ | { | ||
// Display Properties | // Display Properties | ||
MessageBoxW (NULL,pAMessage- | MessageBoxW (NULL,pAMessage->Subject.bstrVal,NULL,MB_OK); | ||
// Get next Message | // Get next Message | ||
pAMessage = NULL; | pAMessage = NULL; | ||
pAMessage = pMessages- | pAMessage = pMessages->GetNext(); | ||
} | } | ||
// Logoff of the MAPI Session | // Logoff of the MAPI Session | ||
pSession- | pSession->Logoff(); | ||
} | } | ||
catch (_com_error & | catch (_com_error &e) | ||
{ | { | ||
dump_com_error(e); | dump_com_error(e); |
Latest revision as of 12:30, 21 July 2020
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