//获得SIM中联系人信息。
LPARAM DoShowSimContact(HWND hWnd, WORD idItem, HWND hwndCtl, WORD wNotifyCode){ MessageBox(NULL, TEXT("start show sim contact"),TEXT("info"),MB_YESNO); HSIM lphSim; HRESULT hr = SimInitialize(0, NULL, 0, &lphSim); if(FAILED(hr)) { MessageBox(NULL, TEXT("initialize failure!"),TEXT("error"),MB_YESNO); return 0 ; }
DWORD dwUsed,dwTotal; hr = SimGetPhonebookStatus(lphSim, SIM_PBSTORAGE_SIM, &dwUsed, &dwTotal);
TCHAR buf[20];
swprintf(buf, TEXT("dwUsed = %d"), dwUsed);
MessageBox(NULL, buf ,TEXT("dwUsed"),MB_YESNO); for(int i=0; i<dwUsed; i++) {
//对结构初始话以下 SIMPHONEBOOKENTRY phoneent; memset(&phoneent,0,sizeof(phoneent)); phoneent.cbSize = sizeof(phoneent); if (SUCCEEDED(SimReadPhonebookEntry(lphSim, SIM_PBSTORAGE_SIM, i+1, &phoneent))) { TCHAR name[32]; TCHAR phone[32];MessageBox(NULL, phoneent.lpszText ,TEXT("info1"),MB_YESNO); wcsncpy(name, phoneent.lpszText,31); // 姓名 wcsncpy(phone, phoneent.lpszAddress,31); // 电话 _tcscat(name, phone); MessageBox(NULL, name ,TEXT("info"),MB_YESNO); }
}
//最后别忘了清理 SimDeinitialize(lphSim); lphSim = NULL;
return 0;}//获得Outlook联系人信息
BOOL GetOutlookContacts(IPOutlookItemCollection * pItemCol){ BSTR bstrFirstName; BSTR bstrLastName; BSTR bstrPhoneNumber; BSTR bstrContactInfo; IContact * pContact = NULL; int cItems = 0; pItemCol->get_Count(&cItems); for (int i = 1; i <= cItems; i++) { if (SUCCEEDED(pItemCol->Item (i, reinterpret_cast<IDispatch**>(&pContact)))) { // grab properties pContact->get_FirstName(&bstrFirstName); pContact->get_LastName(&bstrLastName); pContact->get_HomeTelephoneNumber(&bstrPhoneNumber);
// allocate a buffer for all the properties plus a comma, space. newline, and terminating null bstrContactInfo = SysAllocStringByteLen(NULL, SysStringByteLen(bstrFirstName) + SysStringByteLen(bstrLastName) + SysStringByteLen(bstrPhoneNumber) + (4*sizeof(OLECHAR))); // copy the strings into one _tcscpy(bstrContactInfo, bstrLastName); _tcscat(bstrContactInfo, _T(", ")); _tcscat(bstrContactInfo, bstrFirstName); _tcscat(bstrContactInfo, _T("/n")); _tcscat(bstrContactInfo, bstrPhoneNumber); // add it to the listview AddToList(bstrContactInfo);
// clean up SysFreeString(bstrFirstName); SysFreeString(bstrLastName); SysFreeString(bstrPhoneNumber); SysFreeString(bstrContactInfo); pContact->Release(); } } if(!AddSIMContactsFolderText()) { MessageBox(NULL, TEXT("add sim failure!"),TEXT("error"),MB_YESNO);
} return TRUE; }