分类: C/C++
2006-09-22 11:08:11
一、包含头文件及一个指针函数声明
// Outlook Express中通讯薄部分
#include
// 内部涵数声明
typedef HRESULT (WINAPI *fWABOpen)(LPADRBOOK*,LPWABOBJECT*,LPWAB_PARAM,DWORD);
二、下面的代码写在一个函数里面就可以了
// TODO: Add your control notification handler code here
HRESULT hRes;
LPADRBOOK lpAdrBook;
LPWABOBJECT lpWABObject;
LPWAB_PARAM lpWABParam = NULL;
DWORD Reserved2 = NULL;
HINSTANCE hinstLib;
hinstLib = LoadLibrary("c:\\Program Files\\Common Files\\System\\wab32");
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;
hRes = lpAdrBook->OpenEntry(
lpcbEntryID,
lpEntryID,
NULL,
ulFlags,
&ulObjType,
&lpUnk
);
ulFlags = NULL;
if (ulObjType == MAPI_ABCONT)
{
IABContainer *lpContainer = static_cast
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
);
// m_ListEmail.ResetContent();
for(ULONG i=0;i
{
SRow *lpRow = &lpRows->aRow[i];
CString strTemp;
for(ULONG j=0;j
{
SPropValue *lpProp = &lpRow->lpProps[j];
if (lpProp->ulPropTag == PR_DISPLAY_NAME_A)
strTemp = strTemp + " 名字: " + (char *)lpProp->Value.lpszA;
if (lpProp->ulPropTag == PR_EMAIL_ADDRESS_A)
strTemp = strTemp + " Email: " + (char *)lpProp->Value.lpszA;
if (lpProp->ulPropTag == PR_NICKNAME_A)
strTemp = strTemp + " 呢称: " + (char *)lpProp->Value.lpszA;
if (lpProp->ulPropTag == PR_ADDRTYPE_A)
strTemp = strTemp + " 类型: " + (char *)lpProp->Value.lpszA;
if (lpProp->ulPropTag == PR_CALLBACK_TELEPHONE_NUMBER_A)
strTemp = strTemp + "电话:" + (char *)lpProp->Value.lpszA;
}
// m_ListEmail.AddString(strTemp);
::AfxMessageBox(strTemp);
lpWABObject->FreeBuffer(lpRow);
}
lpWABObject->FreeBuffer(lpRows);
}
}
//FreeLibrary(hinstLib);
}