Brief introduction
If you want to get the contents of your native Address book (Outlook Express and Outlook2000), such as your contact name, contact e-mail address, and so on, you can try the following method. Here is a sample program that uses this method with VC6 to run the effect:
Due to the different methods used to read the contents of the newsletter in Outlook Express (System band) and Outlook2000 (Office2000), the following is a separate summary.
First, read the system with the Outlook Express communication thin method
Basic ideas
Read out the main contents of the communication book by loading the Wab32.dll file, which is generally located under the path "< disk >\program Files\Common Files\system\", and then getting the process address of its inner number wabopen.
Concrete implementation
One, contains the communication thin header file and declares the internal function
#include <wab.h> // 通讯薄头文件
// 内部函数声明
typedef HRESULT (WINAPI *fWABOpen)(LPADRBOOK*,LPWABOBJECT*,LPWAB_PARAM,DWORD);
Second, read the specific content of the detailed code
Read the contents of the Communication book (type, name, EMAIL)
void Cgetemaildlg::onok ()
{
HRESULT hres;
Lpadrbook Lpadrbook;
Lpwabobject Lpwabobject;
Lpwab_param Lpwabparam = NULL;
DWORD Reserved2 = NULL;
HINSTANCE hInstLib;
hInstLib = LoadLibrary ("D:\\Program Files\\Common Files\\system\\wab32");
Fwabopen Procwabopen;
if (hInstLib!= NULL)
{
Gets the process address of the "Wab32.dll" internal number 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 <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,//Get all rows
0,
&lprows
);
M_listemail.resetcontent ();
for (ULONG i=0;i<lprows->crows;i++)
{
Srow *lprow = &lpRows->aRow[i];
CString strtemp;
for (ULONG j=0;j<lprow->cvalues;j++)
{
SPropValue *lpprop = &lpRow->lpProps[j];
if (Lpprop->ulproptag = = pr_display_name_a)
strtemp = strtemp + "Name:" + (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 + "What is called:" + (char *) lpprop->value.lpsza;
if (Lpprop->ulproptag = = pr_addrtype_a)
strtemp = strtemp + "type:" + (char *) lpprop->value.lpsza;
}
M_listemail.addstring (strtemp);
Lpwabobject->freebuffer (Lprow);
}
Lpwabobject->freebuffer (lprows);
}
}
FreeLibrary (hInstLib);
The Set Read button is invalid after successful read
cbutton* pbtn = (cbutton*) GetDlgItem (IDOK);
Pbtn->enablewindow (FALSE);
}
}