Microsoft KB Archive/173550: Difference between revisions
From BetaArchive Wiki
m (Text replacement - ">" to ">") |
m (Text replacement - """ to """) |
||
Line 70: | Line 70: | ||
// To the Developer: | // To the Developer: | ||
// There are a couple of sections of this code with action items marked | // There are a couple of sections of this code with action items marked | ||
// | // "TO DO:" for you to resolve before it will successfully run. | ||
// TO DO: Uncomment the appropriate statement | // TO DO: Uncomment the appropriate statement | ||
Line 77: | Line 77: | ||
// #import <olemsg32.dll> no_namespace | // #import <olemsg32.dll> no_namespace | ||
// If you are using CDO (1.2, 1.21) uncomment the next line: | // If you are using CDO (1.2, 1.21) uncomment the next line: | ||
// #import | // #import "c:\\program files\\common files\\system\\mapi\\1033\\cdo.dll | ||
#include <assert.h> | #include <assert.h> | ||
Line 85: | Line 85: | ||
void dump_com_error(_com_error &e) | 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 109: | Line 109: | ||
// Create a MAPI.Session pointer | // Create a MAPI.Session pointer | ||
// For CDO (1.1) uncomment the next line | // For CDO (1.1) uncomment the next line | ||
// SessionPtr pSession( | // SessionPtr pSession("MAPI.Session"); | ||
// For CDO (1.2, 1.21) uncomment the next line | // For CDO (1.2, 1.21) uncomment the next line | ||
// _SessionPtr pSession( | // _SessionPtr pSession("MAPI.Session"); | ||
// Logon prompting the user for a profile | // Logon prompting the user for a profile | ||
Line 140: | Line 140: | ||
// To the Developer: | // To the Developer: | ||
// There are a couple of sections of this code with action items marked | // There are a couple of sections of this code with action items marked | ||
// | // "TO DO:" for you to resolve before it will successfully run. | ||
// TO DO: Uncomment the appropriate statement | // TO DO: Uncomment the appropriate statement | ||
Line 147: | Line 147: | ||
// #import <olemsg32.dll> no_namespace | // #import <olemsg32.dll> no_namespace | ||
// If you are using CDO (1.2, 1.21) uncomment the next line: | // If you are using CDO (1.2, 1.21) uncomment the next line: | ||
// #import | // #import "c:\\program files\\common files\\system\\mapi\\1033\\cdo.dll | ||
#include <assert.h> | #include <assert.h> | ||
Line 155: | Line 155: | ||
void dump_com_error(_com_error &e) | 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 179: | Line 179: | ||
// Create a MAPI.Session pointer | // Create a MAPI.Session pointer | ||
// For CDO (1.1) uncomment the next line | // For CDO (1.1) uncomment the next line | ||
// SessionPtr pSession( | // SessionPtr pSession("MAPI.Session"); | ||
// For CDO (1.2, 1.21) uncomment the next line | // For CDO (1.2, 1.21) uncomment the next line | ||
// _SessionPtr pSession( | // _SessionPtr pSession("MAPI.Session"); | ||
// Logon using the specified profile | // Logon using the specified profile | ||
pSession->Logon( | pSession->Logon("YourValidProfileNameGoesHere"); | ||
// The remaining functionality of your app takes place here | // The remaining functionality of your app takes place here | ||
Line 219: | Line 219: | ||
// that the mailbox name is not the messaging user's display | // that the mailbox name is not the messaging user's display | ||
// name, but rather the alias or account name used internally | // name, but rather the alias or account name used internally | ||
// by the user's organization. For example, | // by the user's organization. For example, "johnd" should be | ||
// used instead of | // used instead of "John Doe". | ||
// | // | ||
// For an anonymous profile, the format is: | // For an anonymous profile, the format is: | ||
// | // | ||
// <server distinguished name> + \n\n + | // <server distinguished name> + \n\n + "anon" | ||
// | // | ||
// where the distinguished name of the server takes the form: | // where the distinguished name of the server takes the form: | ||
Line 237: | Line 237: | ||
// To the Developer: | // To the Developer: | ||
// There are a couple of sections of this code with action items marked | // There are a couple of sections of this code with action items marked | ||
// | // "TO DO:" for you to resolve before it will successfully run. | ||
// TO DO: Uncomment the appropriate statement | // TO DO: Uncomment the appropriate statement | ||
Line 244: | Line 244: | ||
// #import <olemsg32.dll> no_namespace | // #import <olemsg32.dll> no_namespace | ||
// If you are using CDO (1.2, 1.21) uncomment the next line: | // If you are using CDO (1.2, 1.21) uncomment the next line: | ||
// #import | // #import "c:\\program files\\common files\\system\\mapi\\1033\\cdo.dll | ||
#include <assert.h> | #include <assert.h> | ||
Line 252: | Line 252: | ||
void dump_com_error(_com_error &e) | 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 276: | Line 276: | ||
// Create a MAPI.Session pointer | // Create a MAPI.Session pointer | ||
// For CDO (1.1) uncomment the next line | // For CDO (1.1) uncomment the next line | ||
// SessionPtr pSession( | // SessionPtr pSession("MAPI.Session"); | ||
// For CDO (1.2, 1.21) uncomment the next line | // For CDO (1.2, 1.21) uncomment the next line | ||
// _SessionPtr pSession( | // _SessionPtr pSession("MAPI.Session"); | ||
// Create the params used in the Logon including the | // Create the params used in the Logon including the | ||
Line 293: | Line 293: | ||
//Modify malloc param to size needed by your app | //Modify malloc param to size needed by your app | ||
pstrProfileInfo = (char *) malloc (27) ; | pstrProfileInfo = (char *) malloc (27) ; | ||
strcpy (pstrProfileInfo, | strcpy (pstrProfileInfo, "MyServerName\nMyMailBoxName") ; | ||
// Logon using the specified profile | // Logon using the specified profile | ||
// params: profileName, profilePassword, showDialog, | // params: profileName, profilePassword, showDialog, | ||
// newSession, parentWindow, NoMail, ProfileInfo | // newSession, parentWindow, NoMail, ProfileInfo | ||
pSession->Logon( | pSession->Logon("", | ||
"", | |||
vBoolF, | vBoolF, | ||
vBoolT, | vBoolT, | ||
Line 307: | Line 307: | ||
// Display generated ProfileName to prove the we are logged on | // Display generated ProfileName to prove the we are logged on | ||
MessageBoxW(NULL,pSession->Name.bstrVal,L | MessageBoxW(NULL,pSession->Name.bstrVal,L"",MB_OK) ; | ||
// The remaining functionality of your app takes place here | // The remaining functionality of your app takes place here |
Revision as of 11:06, 21 July 2020
Article ID: 173550
Article Last Modified on 8/24/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 Q173550
SUMMARY
This article covers these three primary ways to create and then logon to a CDO (1.1, 1.2, 1.21) Session from Visual C++:
- With prompt for Profile
- Without prompt for Profile
- Creating a dynamic Profile programmatically
MORE INFORMATION
With Prompt for Profile
/**********************************************************/ // W_PROMPT.CPP // ------------ // This program demonstrates how to use the Session->Logon // of the CDO (1.1, 1.2, 1.21) Library via VC++, to prompt // the user for a Profile at Logon. This sample requires // VC++ version 5.0 or higher. /**********************************************************/ // To the Developer: // There are a couple of sections of this code with action items marked // "TO DO:" for you to resolve before it will successfully run. // TO DO: Uncomment the appropriate statement // and provide the full path to the dll. // If you are using CDO (1.1) uncomment the next line: // #import <olemsg32.dll> no_namespace // If you are using CDO (1.2, 1.21) uncomment the next line: // #import "c:\\program files\\common files\\system\\mapi\\1033\\cdo.dll #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 { // TO DO: // Create a MAPI.Session pointer // For CDO (1.1) uncomment the next line // SessionPtr pSession("MAPI.Session"); // For CDO (1.2, 1.21) uncomment the next line // _SessionPtr pSession("MAPI.Session"); // Logon prompting the user for a profile pSession->Logon(vtMissing, vtMissing, true); // The remaining functionality of your app takes place here // Logoff of the MAPI Session pSession->Logoff(); } catch (_com_error &e) { dump_com_error(e); } }
Without Prompt for Profile
/**********************************************************/ // WO_PROMPT.CPP // ------------- // This program demonstrates how to use the Session->Logon // of the CDO (1.1, 1.2, 1.21) Library via VC++, to not // prompt the user for a Profile at Logon. This sample // requires VC++ version 5.0 or higher. /**********************************************************/ // To the Developer: // There are a couple of sections of this code with action items marked // "TO DO:" for you to resolve before it will successfully run. // TO DO: Uncomment the appropriate statement // and provide the full path to the dll. // If you are using CDO (1.1) uncomment the next line: // #import <olemsg32.dll> no_namespace // If you are using CDO (1.2, 1.21) uncomment the next line: // #import "c:\\program files\\common files\\system\\mapi\\1033\\cdo.dll #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 { // TO DO: // Create a MAPI.Session pointer // For CDO (1.1) uncomment the next line // SessionPtr pSession("MAPI.Session"); // For CDO (1.2, 1.21) uncomment the next line // _SessionPtr pSession("MAPI.Session"); // Logon using the specified profile pSession->Logon("YourValidProfileNameGoesHere"); // The remaining functionality of your app takes place here // Logoff of the MAPI Session pSession->Logoff(); } catch (_com_error &e) { dump_com_error(e); } }
Creating a Dynamic Profile Programmatically
/**********************************************************/ // DYN_PROF.CPP // ------------ // This program demonstrates how to use the Session->Logon // of the CDO (1.1, 1.2, 1.21) Library via VC++, to create // a dynamic Profile at Logon. This is the likely method to // use if the application will be run as a Windows NT Service. // // The key point of this sample is the final parameter to the // logon, which allows for creation of a temporary profile // for the session. The CDO (1.1, 1.2, 1.21) Library will // generate a random name for the profile. // // For an authenticated profile, the format of the string is: // // <server name> + \n + <mailbox name> // // where the server and mailbox names can be unresolved. Note // that the mailbox name is not the messaging user's display // name, but rather the alias or account name used internally // by the user's organization. For example, "johnd" should be // used instead of "John Doe". // // For an anonymous profile, the format is: // // <server distinguished name> + \n\n + "anon" // // where the distinguished name of the server takes the form: // // /o=<enterprise>/ou=<site>/cn=Configuration/cn=Servers/cn=<server> // // // This sample demonstrates an authenticated logon, and // requires Visual C++ version 5.0 or higher. /**********************************************************/ // To the Developer: // There are a couple of sections of this code with action items marked // "TO DO:" for you to resolve before it will successfully run. // TO DO: Uncomment the appropriate statement // and provide the full path to the dll. // If you are using CDO (1.1) uncomment the next line: // #import <olemsg32.dll> no_namespace // If you are using CDO (1.2, 1.21) uncomment the next line: // #import "c:\\program files\\common files\\system\\mapi\\1033\\cdo.dll #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 { // TO DO: // Create a MAPI.Session pointer // For CDO (1.1) uncomment the next line // SessionPtr pSession("MAPI.Session"); // For CDO (1.2, 1.21) uncomment the next line // _SessionPtr pSession("MAPI.Session"); // Create the params used in the Logon including the // string used for the ProfileInfo VARIANTARG vBoolF; vBoolF.vt = VT_BOOL; vBoolF.boolVal = FALSE; VARIANTARG vBoolT; vBoolT.vt = VT_BOOL; vBoolT.boolVal = TRUE; char * pstrProfileInfo ; //Modify malloc param to size needed by your app pstrProfileInfo = (char *) malloc (27) ; strcpy (pstrProfileInfo, "MyServerName\nMyMailBoxName") ; // Logon using the specified profile // params: profileName, profilePassword, showDialog, // newSession, parentWindow, NoMail, ProfileInfo pSession->Logon("", "", vBoolF, vBoolT, vBoolF, vBoolF, pstrProfileInfo); // Display generated ProfileName to prove the we are logged on MessageBoxW(NULL,pSession->Name.bstrVal,L"",MB_OK) ; // The remaining functionality of your app takes place here // Logoff of the MAPI Session pSession->Logoff(); } catch (_com_error &e) { dump_com_error(e); } }
REFERENCES
For information on obtaining the CDO (1.x) Library, please see the following article in the Microsoft Knowledge Base:
171440 INFO: Where to Acquire the CDO (1.x) Libraries
Keywords: kbhowto kbmsg kbcode KB173550