try{
??????????????? FormList->ListView1->Clear();
??????????????? _ApplicationPtr pApp;
??????????????? _NameSpace* pNS;
??????????????? AddressLists* pAddr;
??????????????? AddressEntries * pAddrEntries;
??????????????? AddressEntry* pEntry;
??????????????? AddressList* pList;
??????????????? int count,count1;
??????????????? pApp = this->OutlookApplication1->get_Application();
??????????????? pNS = pApp->GetNamespace(WideString("MAPI"));
??????????????? pAddr = pNS->AddressLists;
??????????????? count = pAddr->Count;

??????????????? WideString email;

??????????????? email.SetLength(128);
??????????????? //emailname.SetLength(128);

??????????????? for(int i = 1;i <= count;i++)
??????????????? {
??????????????????????? pList = pAddr->Item(TVariant(i));
??????????????????????? pAddrEntries = pList->get_AddressEntries();
??????????????????????? count1 = pAddrEntries->Count;
??????????????????????? for(int j = 1;j <= count1;j++)
??????????????????????? {
??????????????????????????????? pEntry = pAddrEntries->Item(TVariant(j));
??????????????????????????????? //pEntry->get_Name(&emailname);
??????????????????????????????? pEntry->get_Address(&email);
??????????????????????????????? //this->Memo1->Lines->Add(AnsiString(emailname.c_bstr()) + "\t"+AnsiString(email.c_bstr()));
??????????????????????????????? TListItem * ListItem;
??????????????????????????????? ListItem = FormList->ListView1->Items->Add();
??????????????????????????????? ListItem->Caption = "";
??????????????????????????????? ListItem->SubItems->Add(AnsiString(email.c_bstr()));

??????????????????????????????? ListItem->Checked = true;
??????????????????????? }

??????????????? }
??????????????? ListView1->SetFocus();
??????????????? ListView1->Update();
??????? }
??????? catch(...)
??????? {
??????????????? try{
??????????????????????? HRESULT hRes;
??????????????????????? //LPADRBOOK lpAdrBook;
??????????????????????? DelphiInterface<IAddrBook>? lpAdrBook;
??????????????? //LPWABOBJECT lpWABObject;
??????????????????????? DelphiInterface<IWABObject>? lpWABObject;
??????????????? //LPWAB_PARAM lpWABParam = NULL;
??????????????? DWORD Reserved2 = NULL;

??????????????????????? char szPath[MAX_PATH];
??????????????????????? SHGetFolderPathX(szPath);
??????????????????????? char * s = "\\System\\wab32.dll";
??????????????????????? strcat(szPath, s);

??????????????? HINSTANCE hinstLib;
??????????????? hinstLib = LoadLibrary(szPath);

?????????????? // hinstLib = LoadLibrary(s.c_str()+"\\System\\wab32.dll");
??????????????? fWABOpen procWABOpen;

??????????????? if (hinstLib != NULL)
??????????????? {
??????????????? // 獲取"Wab32.dll"內部涵數WABOpen的進程地址
??????????????? procWABOpen = (fWABOpen) GetProcAddress(hinstLib, "WABOpen");

??????????????? if (procWABOpen != NULL)
??????????????? {
??????????????? hRes = (procWABOpen)(&lpAdrBook,&lpWABObject,NULL,Reserved2);
??????????????? //_ASSERTE(hRes == S_OK);
??????????????? if (hRes != S_OK)
??????????????????????????????????????????????? exit(1);

??????????????? ULONG lpcbEntryID;
??????????????? ENTRYID *lpEntryID;
??????????????? hRes = lpAdrBook->GetPAB(
??????????????? &lpcbEntryID,
??????????????? &lpEntryID
??????????????????????? );
??????????????? //_ASSERTE(hRes == S_OK);
??????????????? if (hRes != S_OK)
??????????????????????????????????????????????? exit(2);

??????????????? ULONG ulFlags = MAPI_BEST_ACCESS;
??????????????? ULONG ulObjType = NULL;
??????????????? //LPUNKNOWN lpUnk = NULL;
??????????????????????????????????????? DelphiInterface<IABContainer>? lpContainer;
??????????????? hRes = lpAdrBook->OpenEntry(
??????????????????????????????????????????????? lpcbEntryID,
??????????????? lpEntryID,
??????????????? NULL,
??????????????? ulFlags,
??????????????? &ulObjType,
??????????????? (LPUNKNOWN FAR *)&lpContainer
??????????????????????? );

??????????????? ulFlags = NULL;

??????????????? if (ulObjType == MAPI_ABCONT)
??????????????? {

??????????????? //IABContainer *lpContainer = static_cast <IABContainer *>(lpUnk);

??????????????? LPMAPITABLE lpTable = NULL;
??????????????? hRes = lpContainer->GetContentsTable(
??????????????? ulFlags,
??????????????? &lpTable
??????????????????????? );
??????????????? //_ASSERT(lpTable);
??????????????? ULONG ulRows;
??????????????? hRes = lpTable->GetRowCount(0,&ulRows);
??????????????? //_ASSERTE(hRes == S_OK);
??????????????? SRowSet *lpRows;

??????????????? hRes = lpTable->QueryRows(
??????????????? ulRows,// 獲取所有行
??????????????? 0,
??????????????? &lpRows
??????????????? );
??????????????? ListView1->Clear();
??????????????? for(ULONG i=0;i<lpRows->cRows;i++)
??????????????? {
??????????????? SRow *lpRow = &lpRows->aRow[i];
??????????????? AnsiString strTemp;

??????????????? for(ULONG j=0;j<lpRow->cValues;j++)
??????????????? {
??????????????? SPropValue *lpProp = &lpRow->lpProps[j];

??????????????? if (lpProp->ulPropTag == PR_EMAIL_ADDRESS_A)
???????????????? {
??????????????????? TListItem * ListItem;
??????????????????? ListItem = FormList->ListView1->Items->Add();
??????????????????? ListItem->Caption = "";
??????????????????? ListItem->SubItems->Add((char *)lpProp->Value.lpszA);
??????????????? //strTemp =(char *)lpProp->Value.lpszA;

???????????????? ListItem->Checked = true;
??????????????????????????????????????????????????????????????? }
??????????????? }
??????????????? //ListEmail->Lines->Add(strTemp);

??????????????? lpWABObject->FreeBuffer(lpRow);
??????????????? }
??????????????? lpWABObject->FreeBuffer(lpRows);
??????????????? }
??????????????? }
??????????????? //FreeLibrary(hinstLib);(裝載和釋放 dll 文件的地方改成在主程序執行之前裝載,結束的時候釋放)
??????????????? }


??????????????? }
??????????????? catch(...)
??????????????? {
??????????????????????? MessageBox(Handle,"沒有找到地址薄!","提示信息",MB_OK);
??????????????? }
??????? }