// Set address list search order to Custom int Setcustomization(IMAPISession &lpSession) { HRESULT hr; LPPROFSECT lpProfileSection = NULL; LPSPropValue lpPropValue = NULL; LONG FAR * ulPropCnt = NULL; LPSPropValue FAR * pProps = NULL; hr = lpSession.OpenProfileSection((LPMAPIUID)&IID_CAPONE_PROF, NULL, MAPI_MODIFY , &lpProfileSection); if (FAILED (hr)) { cerr << "Error: Could not open the CAPONE profile section" <<endl; return 1; } //hr = HrGetOneProp(lpProfileSection, PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY, &lpPropValue);// good for select automatically hr = HrGetOneProp(lpProfileSection, PR_AB_SEARCH_PATH_CUSTOMIZATION, &lpPropValue); if (FAILED (hr)) { lpProfileSection->Release(); cerr << "Error: Could not open the property of the address book to set address list search order to Custom" <<endl; return 2; } //cout << "Server DN: %d\n", lpPropValue->Value.b; lpPropValue->Value.l = SEARCHPATHREORDERTYPE_RAW; hr = HrSetOneProp(lpProfileSection, lpPropValue); if (FAILED (hr)) { MAPIFreeBuffer(lpPropValue); cerr << "Error: Could not set the property of the address list search order to Custom" <<endl; return 3; // can't get the prop } cout << "Configured address list search order to be Custom" <<endl; return S_OK; }
// Get MAPI unique guid, guaranteed by MAPI to be unique for all profiles. HRESULT GetMAPIUniqueProfileId(LPMAPISUP lpMAPISup, tstring* lpstrUniqueId) { HRESULT hr = hrSuccess; LPPROFSECT lpProfSect = NULL; LPSPropValue lpsPropValue = NULL; hr = lpMAPISup->OpenProfileSection((LPMAPIUID)&MUID_PROFILE_INSTANCE, 0, &lpProfSect); if(hr != hrSuccess) goto exit; hr = HrGetOneProp(lpProfSect, PR_SEARCH_KEY, &lpsPropValue); if(hr != hrSuccess) goto exit; *lpstrUniqueId = bin2hext(lpsPropValue->Value.bin.cb, lpsPropValue->Value.bin.lpb); exit: if(lpsPropValue) MAPIFreeBuffer(lpsPropValue); if(lpProfSect) lpProfSect->Release(); return hr; }
void CProviderTableDlg::OnOpenProfileSection() { HRESULT hRes = S_OK; if (!m_lpProviderAdmin) return; CEditor MyUID( this, IDS_OPENPROFSECT, IDS_OPENPROFSECTPROMPT, 2, CEDITOR_BUTTON_OK|CEDITOR_BUTTON_CANCEL); MyUID.InitPane(0, CreateDropDownGuidPane(IDS_MAPIUID, false)); MyUID.InitPane(1, CreateCheckPane(IDS_MAPIUIDBYTESWAPPED, false, false)); WC_H(MyUID.DisplayDialog()); if (S_OK != hRes) return; GUID guid = {0}; SBinary MapiUID = {sizeof(GUID),(LPBYTE) &guid}; (void) MyUID.GetSelectedGUID(0, MyUID.GetCheck(1), &guid); LPPROFSECT lpProfSect = NULL; EC_H(OpenProfileSection( m_lpProviderAdmin, &MapiUID, &lpProfSect)); if (lpProfSect) { LPMAPIPROP lpTemp = NULL; EC_MAPI(lpProfSect->QueryInterface(IID_IMAPIProp,(LPVOID*) &lpTemp)); if (lpTemp) { EC_H(DisplayObject( lpTemp, MAPI_PROFSECT, otContents, this)); lpTemp->Release(); } lpProfSect->Release(); } MAPIFreeBuffer(MapiUID.lpb); } // CProviderTableDlg::OnOpenProfileSection
STDMETHODIMP ZybraxiSoft::CMailbox::GetServerNameFromProfile(TSTRING & sServerName) { HRESULT hr = S_OK; LPSERVICEADMIN lpSvcAdmin = NULL; LPPROFSECT lpProfSect = NULL; LPSPropValue lpSPropServer = NULL; // Get the services admin // See https://msdn.microsoft.com/en-us/library/cc765886(v=office.15).aspx if (SUCCEEDED(hr = m_lpSession->AdminServices( NULL, // Reserved - must be zero &lpSvcAdmin))) // pointer to pointer to the service admin obj { // Open the profile section // see https://msdn.microsoft.com/en-us/library/office/cc839895.aspx if (SUCCEEDED(hr = lpSvcAdmin->OpenProfileSection( (LPMAPIUID)pbGlobalProfileSectionGuid, // lpUID NULL, // lpInterface; NULL - IProfSect NULL, // ulFlags - no flags set &lpProfSect))) { // Get the property value for the server if (SUCCEEDED(hr = HrGetOneProp( lpProfSect, // pmp; pointer to IMAPIProp interface PR_PROFILE_HOME_SERVER, // ulPropTag &lpSPropServer))) // ppprop; pointer to a pointer to an SPropValue { // Now the tricky part; profile parts are all ASCII so we need to know // whether to convert it or not. This is going to depend on whether our // TSTRING resolves to wstring or simply string wstring* wsPtr = NULL; wsPtr = dynamic_cast<wstring*>(&sServerName); if (wsPtr) // Cast succeeded, we're dealing with wstring { std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; sServerName = converter.from_bytes(lpSPropServer->Value.lpszA); } else { sServerName = TSTRING(lpSPropServer->Value.LPSZ); } } else { ERROR_MSG_W_HR("Unable to get the PR_PROFILE_HOME_SERVER", hr); goto CLEANUP; } } else { ERROR_MSG_W_HR("Unable to open the profile section", hr); goto CLEANUP; } } else { ERROR_MSG_W_HR("Unable to get the services admin", hr); } CLEANUP: if (lpSPropServer) { MAPIFreeBuffer(lpSPropServer); lpSPropServer = NULL; } if (lpProfSect) { lpProfSect->Release(); lpProfSect = NULL; } if (lpSvcAdmin) { lpSvcAdmin->Release(); lpSvcAdmin = NULL; } return hr; }