How to retrieve a IM field data from a contact?
Locked
-
Friday, December 26, 2008 3:58 PM
How to retrieve a IM field data from a contact?- Edited by Xiaoyun Li – MSFT Monday, December 29, 2008 11:22 AM
Answers
-
Friday, December 26, 2008 4:18 PM
As we know, we can use an IPOutlookApp interface to retrieve information from a contact. To retrieve the information we can get the contact folder and use the IContact interface to get each contact item. However the IContact interface doesn't provide a method to get IM, NickName related data.
We can use IItem, which provides getprops method to get IM,NickName fields of data.
Note: You must use the IPOutlookApp2 interface, which adds a GetItemFromOidEx method to get the contact item IItem interface.
Below is a sample:
void CPoomViewTestDlg::OnBnClickedButton3() { CoInitializeEx( NULL, 0); IPOutlookApp2 * m_Outlook; HRESULT hr = CoCreateInstance(_uuidof(Application), NULL, CLSCTX_INPROC_SERVER, _uuidof(IPOutlookApp), (LPVOID*)&m_Outlook); m_Outlook->Logon(NULL); //Search contact only IFolder * pFolder=NULL; IPOutlookItemCollection *ipItemCollection=NULL; m_Outlook->GetDefaultFolder(OlDefaultFolders::olFolderContacts,&pFolder); int count=0; BSTR firstname; BSTR strIM; if(pFolder) { pFolder->get_Items(&ipItemCollection); if(ipItemCollection) { ipItemCollection->get_Count(&count); //get first contact information IContact *pContact; IItem *pItem; if (SUCCEEDED(ipItemCollection->Item(1,reinterpret_cast<IDispatch**>(&pContact)))) { CEOID oid = 0; pContact->get_Oid((long*)&oid); //get IItem interface m_Outlook->GetItemFromOidEx(oid, 0, &pItem); } // TO DO: Add your control notification handler code here HRESULT hr = E_FAIL; CEPROPVAL *buf = NULL; ULONG cbBuffer = 0; HANDLE hHeap = GetProcessHeap(); CEPROPID rgPropId[1]; rgPropId[0] =PIMPR_IM1_ADDRESS; cbBuffer = 0; hr = pItem->GetProps(rgPropId,CEDB_ALLOWREALLOC,1,&buf,&cbBuffer,hHeap); CEPROPVAL * ppropval = buf; if(ppropval[0].wFlags!=CEDB_PROPNOTFOUND) { if(LOWORD(ppropval[0].propid) == CEVT_LPWSTR) AfxMessageBox(ppropval[0].val.lpwstr); } HeapFree(hHeap, 0, buf); pContact->Release(); pContact = NULL; pItem->Release(); pItem=NULL; } } ipItemCollection->Release(); ipItemCollection=NULL; pFolder->Release(); pFolder = NULL; m_Outlook->Logoff(); m_Outlook->Release(); m_Outlook = NULL; }
We can also use IItem::Edit to open the PIM item for editng in its Edit tab. From the code above, we can see that some functions can be done using IItem , but not using IContact. So if IContact doesn't meet your requirements, you can consider IItem if the IItem interface has the method or property.
Related issues:
For more FAQ about Visual Studio Smart Device Development - Native C++ Project, please see Visual Studio Smart Device Development - Native C++ Project FAQ
- Marked As Answer by Xiaoyun Li – MSFT Friday, December 26, 2008 4:20 PM

