Expand|Select|Wrap|Line Numbers
- _ApplicationPtr application("Outlook.Application");
- CComPtr<_NameSpace> ns;
- CComPtr<_NameSpace> session;
- hr = application->GetNamespace(CComBSTR("MAPI"),&session.p);
- if(hr != S_OK) return hr;
- hr = application->get_Session(&session.p);
- if(hr != S_OK) return hr;
- hr = session->Logon(CComVariant(profile),CComVariant(""),CComVariant(false),CComVariant(true));
- if(hr != S_OK) return hr;
- Outlook::OlExchangeConnectionMode connectionMode;
- hr = session->get_ExchangeConnectionMode(&connectionMode);
- CComPtr<Recipient> recp;
- hr = session->get_CurrentUser(&recp.p);
- CComBSTR name;
- hr = recp->get_Name(&name.m_str);
- return hr;
When outlook is closed everything works fine. i.e given an Exchange Server profile i gets its userName.
But when outlook is open there arises two cases,
The outlook is open and an Exchange-Server connection is open. In this case also i get the proper userName.
But when outlook is open in some other session, say an POP3 for some other user, In this case, I fail to get the UserName of the ExchangeServer. Instead I get the UserName of the PoP3 account.
I have tried, using the various combinations for the Logon, but none seems to give the desired results.
Can some-one correct the code so that it returns always the correct user name.