LPMAPIFOLDER CExMapi::GetNextSubFolder(CString& strFolderName,LPMAPIFOLDER pFolder) { if(!m_pHierarchy) return NULL; if(!pFolder) { pFolder=m_pFolder; if(!pFolder) return FALSE; } DWORD dwObjType; LPSRowSet pRows=NULL; LPMAPIFOLDER pSubFolder=NULL; if(m_pHierarchy->QueryRows(1,0,&pRows)==S_OK) { if(pRows->cRows) { if(pFolder->OpenEntry(pRows->aRow[0].lpProps[PROP_ENTRYID].Value.bin.cb,(LPENTRYID)pRows->aRow[0].lpProps[PROP_ENTRYID].Value.bin.lpb, NULL, MAPI_MODIFY, &dwObjType,(LPUNKNOWN*)&pSubFolder)==S_OK) { strFolderName=CString(GetValidString(pRows->aRow[0].lpProps[0])); } } FreeProws(pRows); MAPIFreeBuffer(pRows); } return pSubFolder; }
// if I try to use MAPI_UNICODE when UNICODE is defined I get the MAPI_E_BAD_CHARWIDTH // error so I force narrow strings here LPCTSTR CExMapi::GetProfileName() { if(!m_pSession) return NULL; static CString strProfileName; LPSRowSet pRows=NULL; const int nProperties=2; SizedSPropTagArray(nProperties,Columns)={nProperties,{PR_DISPLAY_NAME_A, PR_RESOURCE_TYPE}}; IMAPITable* pStatusTable; if(m_pSession->GetStatusTable(0,&pStatusTable)==S_OK) { if(pStatusTable->SetColumns((LPSPropTagArray)&Columns, 0)==S_OK) { while(TRUE) { if(pStatusTable->QueryRows(1,0,&pRows)!=S_OK) MAPIFreeBuffer(pRows); else if(pRows->cRows!=1) FreeProws(pRows); else if(pRows->aRow[0].lpProps[1].Value.ul==MAPI_SUBSYSTEM) { strProfileName=(LPSTR)GetValidString(pRows->aRow[0].lpProps[0]); FreeProws(pRows); } else { FreeProws(pRows); continue; } break; } } RELEASE(pStatusTable); } return strProfileName; }
BOOL CExMapi::OpenDefaultMessageStore(LPCTSTR szStore,ULONG ulFlags) { if(!m_pSession) return FALSE; m_ulMDBFlags=ulFlags; LPSRowSet pRows = NULL; const int nProperties = 3; SizedSPropTagArray(nProperties,Columns)={nProperties,{PR_DISPLAY_NAME, PR_ENTRYID, PR_DEFAULT_STORE}}; BOOL bResult = FALSE; IMAPITable* pMsgStoresTable; if(m_pSession->GetMsgStoresTable(0, &pMsgStoresTable) == S_OK) { if(pMsgStoresTable->SetColumns((LPSPropTagArray)&Columns, 0) == S_OK) { while(TRUE) { if(pMsgStoresTable->QueryRows(1,0,&pRows) != S_OK) MAPIFreeBuffer(pRows); else if(pRows->cRows!=1) FreeProws(pRows); else { if(!szStore) { if(pRows->aRow[0].lpProps[2].Value.b) bResult=TRUE; } else { CString strStore = GetValidString(pRows->aRow[0].lpProps[0]); if(strStore.Find(szStore) != -1) bResult = TRUE; } if(!bResult) { FreeProws(pRows); continue; } } break; } if(bResult) { RELEASE(m_pMsgStore); bResult = (m_pSession->OpenMsgStore(NULL,pRows->aRow[0].lpProps[1].Value.bin.cb,(ENTRYID*)pRows->aRow[0].lpProps[1].Value.bin.lpb,NULL,MDB_NO_DIALOG | MAPI_BEST_ACCESS,&m_pMsgStore) == S_OK); FreeProws(pRows); } } RELEASE(pMsgStoresTable); } return bResult; }
// special case of GetValidString to take the narrow string in UNICODE void CExMapi::GetNarrowString(SPropValue& prop,CString& strNarrow) { LPCTSTR s=GetValidString(prop); if(!s) strNarrow=_T(""); else { #ifdef UNICODE // VS2005 can copy directly if(_MSC_VER>=1400) { strNarrow=(char*)s; } else { WCHAR wszWide[256]; MultiByteToWideChar(CP_ACP,0,(LPCSTR)s,-1,wszWide,255); strNarrow=wszWide; } #else strNarrow=s; #endif } }
// if I try to use MAPI_UNICODE when UNICODE is defined I get the MAPI_E_BAD_CHARWIDTH // error so I force narrow strings here BOOL CMAPIEx::GetProfileName(CString& strProfileName) { BOOL bResult=FALSE; #ifndef _WIN32_WCE if(!m_pSession) return FALSE; LPSRowSet pRows=NULL; const int nProperties=2; SizedSPropTagArray(nProperties, Columns)={nProperties,{PR_DISPLAY_NAME_A, PR_RESOURCE_TYPE}}; IMAPITable* pStatusTable; if(m_pSession->GetStatusTable(0, &pStatusTable)==S_OK) { if(pStatusTable->SetColumns((LPSPropTagArray)&Columns, 0)==S_OK) { while(pStatusTable->QueryRows(1, 0, &pRows)==S_OK) { if(pRows->cRows!=1) FreeProws(pRows); else if(pRows->aRow[0].lpProps[1].Value.ul==MAPI_SUBSYSTEM) { strProfileName=(LPSTR)GetValidString(pRows->aRow[0].lpProps[0]); FreeProws(pRows); bResult=TRUE; } else { FreeProws(pRows); continue; } break; } } RELEASE(pStatusTable); } #endif return bResult; }