How to obtain Outlook Express Address Book/Windows Address Book (WAB) Information

Source: Internet
Author: User

 Hresult hR = s_ OK; </P> <p> try <br/> {<br/> lpwabopen lpfnwabopen = NULL; // defined in wabapi. h. <br/> hinstance hinstwab = NULL; </P> <p> cregkey regkey; </P> <p> long nreturn = regkey. open (HKEY_LOCAL_MACHINE, wab_dll_path_key, key_read); <br/> If (nreturn = error_success) <br/>{< br/> ulong nchars = buffer_size; <br/> tchar szvalue [buffer_size]; <br/> nreturn = regkey. querystringvalue ("", szvalue, & nchars); <Br/> regkey. close (); </P> <p> If (nreturn = error_success) <br/> {<br/> If (lstrlen (szvalue)> 0) <br/>{< br/> hresult hR = e_fail; <br/> hinstwab = loadlibrary (szvalue); <br/> If (hinstwab! = NULL) <br/>{< br/> lpfnwabopen = (lpwabopen) getprocaddress (hinstwab, "wabopen"); <br/> If (lpfnwabopen) <br/>{< br/> wab_param Wp = {0}; <br/> WP. cbsize = sizeof (wab_param); <br/> WP. ulflags = wab_enable_profiles; <br/> WP. hwnd = NULL; <br/> WP. szfilename = NULL; <br/> iaddrbook * paddrbook; <br/> ccomptr <iwabobject> pwabobject; </P> <p> hR = lpfnwabopen (& paddrbook, & pwabobject, & WP, 0); <br/> If (succeeded (HR) <Br/>{< br/> ulong cbentryid; <br/> lpentryid pentryid = NULL; <br/> ulong ulobjtype = NULL; </P> <p> hR = paddrbook-> getpab (& cbentryid, & pentryid); <br/> If (succeeded (HR )) <br/>{< br/> ccomptr <iabcontainer> pabcontainer = NULL; <br/> ulong ulflags = mapi_best_access; <br/> hR = paddrbook-> openentry (cbentryid, 0, null, ulflags, & ulobjtype, (lpunknown *) & pabcontainer); <br/> If (succeeded (HR) <br/>{< br/> CC Omptr <imapitable> pmapitable = NULL; </P> <p> hR = pabcontainer-> gethierarchytable (convenient_depth, & pmapitable); <br/> If (succeeded (HR )) <br/>{< br/> ulong ulcount = 0; </P> <p> hR = pmapitable-> getrowcount (0, & ulcount ); <br/> If (succeeded (HR) <br/>{< br/> lpsrowset prowsets = NULL; </P> <p> // hR = hrqueryallrows (pmapitable, (sproptagarray *) & proptagarray, null, null, ulcount, & prowsets); <br/> hR = pmapitab Le-> queryrows (ulcount, 0, & prowsets); <br/> If (succeeded (HR) <br/>{< br/> for (INT I = 0; I <prowsets-> crows; I ++) <br/>{< br/> ulong ulobjecttype; <br/> int nentryidindex =-1; <br/> DWORD dwdepth = 0; </P> <p> tchar szfoldername [buffer_size]; <br/> zeromemory (szfoldername, sizeof (szfoldername )); </P> <p> for (Int J = 0; j <prowsets-> Arow [I]. cvalues; j ++) <br/>{< br/> switch (prowsets-> Arow [I]. lpprops [J]. ul Proptag) <br/>{< br/> case pr_addrtype: <br/> break; <br/> case pr_display_name: <br/> strcpy_s (szfoldername, prowsets-> Arow [I]. lpprops [J]. value. lpsza); <br/> break; <br/> case pr_display_type: <br/> break; <br/> case pr_entryid: <br/> nentryidindex = J; <br/> break; <br/> case pr_depth: <br/> dwdepth = prowsets-> Arow [I]. lpprops [J]. value. l; <br/> break; <br/> case pr_instance_key: <br/> break; <br/> case pr_objec T_type: <br/> ulobjecttype = prowsets-> Arow [I]. lpprops [J]. value. l; <br/> break; <br/> case pr_email_address: <br/> break; <br/> case pr_record_key: <br/> break; <br/> case pr_nickname: <br/> break; <br/> case pr_mobile_telephone_number: <br/> break; </P> <p> case pr_rowid: <br/> break; <br/> case pr_container_flags: <br/> break; <br/> case pr_ AB _provider_id: <br/> break; </P> <p> default: <br/> break; <br/>}</P> <P> If (ulobjecttype = mapi_folder) <br/>{< br/>}</P> <p> If (dwdepth! = 0) & (nentryidindex> = 0) <br/>{< br/> ccomptr <iabcontainer> pcontainer2 = NULL; <br/> hR = pabcontainer-> openentry (prowsets-> Arow [I]. lpprops [nentryidindex]. value. bin. CB, (lpentryid) prowsets-> Arow [I]. lpprops [nentryidindex]. value. bin. LPB, null, ulflags, & ulobjtype, (lpunknown *) & pcontainer2); <br/> If (succeeded (HR )) <br/>{< br/> ccomptr <imapitable> pmapitable2 = NULL; <br/> hR = pcontainer2-> getconten Tstable (0x00100000/* wab_local_containers */, & pmapitable2); <br/> If (succeeded (HR) <br/>{< br/> ulong ulcount2; <br/> pmapitable2-> getrowcount (0, & ulcount2); </P> <p> lpsrowset prowsets2 = NULL; <br/> pmapitable2-> queryrows (ulcount2, 0, & prowsets2); <br/> for (INT I2 = 0; I2 <prowsets2-> crows; I2 ++) <br/>{< br/> tchar szemailaddress [buffer_size]; <br/> zeromemory (szemailaddress, sizeof (szemailaddress); <br /> Tchar szdisplayname [buffer_size]; <br/> zeromemory (szdisplayname, sizeof (szdisplayname); <br/> tchar szmobilephonenumber [buffer_size]; <br/> zeromemory (memory, sizeof (szmobilephonenumber); <br/> tchar szaddresstype [buffer_size]; <br/> zeromemory (szaddresstype, sizeof (szaddresstype )); </P> <p> ulong ulobjecttypecatogory = 0x00; <br/> int nindexobjecttype =-1; </P> <p> int nmailuserentryidinde X =-1; </P> <p> for (INT J2 = 0; J2 <prowsets2-> Arow [I2]. cvalues; J2 ++) <br/>{< br/> switch (prowsets2-> Arow [I2]. lpprops [J2]. ulproptag) <br/>{< br/> case pr_addrtype: <br/> strcpy_s (szaddresstype, prowsets2-> Arow [I2]. lpprops [J2]. value. lpsza); <br/> break; <br/> case pr_display_name: <br/> strcpy_s (szdisplayname, prowsets2-> Arow [I2]. lpprops [J2]. value. lpsza); <br/> break; <br/> case pr_display_type: <br/> brea K; <br/> case pr_entryid: <br/> nmailuserentryidindex = J2; <br/> break; <br/> case pr_instance_key: <br/> break; <br/> case pr_object_type: <br/>{< br/> nindexobjecttype = J2; <br/> If (prowsets2-> Arow [I2]. lpprops [J2]. value. L = mapi_mailuser) <br/>{< br/> ulobjecttypecatogory = mapi_mailuser; <br/>}< br/> else if (prowsets2-> Arow [I2]. lpprops [J2]. value. L = mapi_distlist) <br/>{< br/> ulobjecttypecatogory = m Api_distlist; <br/>}< br/> break; <br/> case pr_email_address: <br/> strcpy_s (szemailaddress, prowsets2-> Arow [I2]. lpprops [J2]. value. lpsza); <br/> break; <br/> case pr_record_key: <br/> break; <br/> case pr_nickname: <br/> break; <br/> case pr_mobile_telephone_number: <br/> strcpy_s (szmobilephonenumber, prowsets2-> Arow [I2]. lpprops [J2]. value. lpsza); <br/> break; </P> <p> default: <br/> break; <br/>}< /P> <p> If (ulobjecttypecatogory = mapi_mailuser) <br/>{< br/> imailuser * pmailuser = NULL; <br/> idistlist * pdistlist = NULL; <br/> ulong ulobjtypemailuser = 0; </P> <p> If (nmailuserentryidindex! =-1) <br/>{< br/> hR = pcontainer2-> openentry (prowsets2-> Arow [I2]. lpprops [nmailuserentryidindex]. value. bin. CB, <br/> (lpentryid) prowsets2-> Arow [I2]. lpprops [nmailuserentryidindex]. value. bin. LPB, null, condition, & ulobjtypemailuser, (lpunknown *) & pmailuser); <br/> If (succeeded (HR) <br/>{< br/> lpsproptagarray lpmailuserproptagarray; <br/> ulong ulpropertycount; <br/> lpspropvalue lpmailuserpropvalu Earray = NULL; </P> <p> hR = pmailuser-> getprops (null, fmapiunicode, & ulpropertycount, & lpmailuserpropvaluearray); <br/> If (succeeded (HR )) <br/>{< br/> If (ulpropertycount> 0) <br/>{< br/> wchar swzemailaddress [buffer_size]; <br/> zeromemory (swzemailaddress, sizeof (swzemailaddress); </P> <p> wchar swzdisplayname [buffer_size]; <br/> zeromemory (swzdisplayname, sizeof (swzdisplayname )); </P> <p> wchar swzmobilepho Nenumber [buffer_size]; <br/> zeromemory (bytes, sizeof (bytes); </P> <p> wchar swzaddresstype [buffer_size]; <br/> zeromemory (swzaddresstype, sizeof (swzaddresstype); </P> <p> lpmessage pmessage = NULL; <br/> imapifolder * pcontactfolder = NULL; </P> <p> if (I = 0) <br/> {<br/> hR = m_pcurrentcontactfolder-> createmessage (null, mapi_deferred_errors, & pmessage ); <br/>}< br/> else <br/> {<Br/> hR = m_pcurrentcontactfolder-> createfolder (folder_generic, szfoldername, "", & local_iid_imapifolder, fmapiunicode, & pcontactfolder ); </P> <p> If (succeeded (HR) <br/>{< br/> spropvalue propfoldervalue [2]; <br/> lpspropproblemarray propfolderproblemarray = NULL; </P> <p> propfoldervalue [0]. ulproptag = pr_container_class_w; <br/> propfoldervalue [0]. dwalignpad = NULL; <br/> propfoldervalue [0]. value. lpszw = L "IPF. contact "; </P> <p> // container, pidtagextendedfolderflags, ptagextendedfolderflags <br/> byte bytempextendflag [] = {0x01, 0x04, 0x00, 0x00, 0x10, 0x00}; <br/> propfoldervalue [1]. dwalignpad = NULL; <br/> propfoldervalue [1]. ulproptag = 0x36da0102; <br/> propfoldervalue [1]. value. bin. CB = 0x00000006; <br/> propfoldervalue [1]. value. bin. LPB = bytempextendflag; </P> <p> pcontactfolder-> setp ROPS (2, propfoldervalue, & tags); <br/> pcontactfolder-> savechanges (keep_open_readwrite); </P> <p> hR = pcontactfolder-> createmessage (null, expires, & pmessage); <br/>}</P> <p> If (succeeded (HR )) <br/>{< br/> lpspropvalue pspproparray = new spropvalue [11]; <br/> lpspropproblemarray lppropproblemarray = NULL; <br/> pspproparray [0]. dwalignpad = NULL; <br/> pspproparray [0]. ul Proptag = pr_message_class_w; <br/> pspproparray [0]. value. lpszw = l "IPM. contact "; </P> <p> pspproparray [1]. dwalignpad = NULL; <br/> pspproparray [1]. ulproptag = pr_message_flags; <br/> pspproparray [1]. value. L = msgflag_read; <br/> pspproparray [1]. value. ul = msgflag_read; </P> <p> pspproparray [2]. dwalignpad = NULL; <br/> pspproparray [2]. ulproptag = 0x802e001f; <br/> cutilities: multibytes2unicode (swzemailaddres S, sizeof (swzemailaddress), szemailaddress); <br/> pspproparray [2]. value. lpszw = swzemailaddress; </P> <p> pspproparray [3]. dwalignpad = NULL; <br/> pspproparray [3]. ulproptag = 0x805b001f; <br/> cutilities: multibytes2unicode (swzemailaddress, sizeof (swzemailaddress), szemailaddress); <br/> pspproparray [3]. value. lpszw = swzemailaddress; </P> <p> pspproparray [3]. dwalignpad = NULL; <br/> pspproparray [3]. ulpropta G = 0x805b001f; <br/> cutilities: multibytes2unicode (swzemailaddress, sizeof (swzemailaddress), szemailaddress); <br/> pspproparray [3]. value. lpszw = swzemailaddress; </P> <p> pspproparray [4]. dwalignpad = NULL; <br/> pspproparray [4]. ulproptag = pr_importance; <br/> pspproparray [4]. value. L = importance_normal; <br/> pspproparray [4]. value. ul = importance_normal; </P> <p> pspproparray [5]. dwalignpad = NULL; <br/> P Spproparray [5]. ulproptag = pr_subject_w; <br/> cutilities: multibytes2unicode (swzdisplayname, sizeof (swzdisplayname), szdisplayname); <br/> pspproparray [5]. value. lpszw = swzdisplayname; </P> <p> pspproparray [6]. dwalignpad = NULL; <br/> pspproparray [6]. ulproptag = pr_display_name_w; <br/> cutilities: multibytes2unicode (swzdisplayname, sizeof (swzdisplayname), szdisplayname); <br/> pspproparray [6]. value. lpsz W = swzdisplayname; </P> <p> pspproparray [7]. dwalignpad = NULL; <br/> pspproparray [7]. ulproptag = pr_message_flags; <br/> pspproparray [7]. value. L = 9; <br/> pspproparray [7]. value. ul = 9; </P> <p> pspproparray [8]. dwalignpad = NULL; <br/> pspproparray [8]. ulproptag = 0x815c001f; <br/> cutilities: multibytes2unicode (swzemailaddress, sizeof (swzemailaddress), szemailaddress); <br/> pspproparray [8]. value. lpszw = swz Emailaddress; </P> <p> pspproparray [9]. dwalignpad = NULL; <br/> pspproparray [9]. ulproptag = 0x8061001f; <br/> cutilities: multibytes2unicode (swzemailaddress, sizeof (swzemailaddress), szemailaddress); <br/> pspproparray [9]. value. lpszw = swzemailaddress; </P> <p> pspproparray [10]. dwalignpad = NULL; <br/> pspproparray [10]. ulproptag = 0x805f001f; <br/> cutilities: multibytes2unicode (swzdisplayname, sizeof (swzdis Playname), szdisplayname); <br/> pspproparray [10]. value. lpszw = swzdisplayname; </P> <p> pmessage-> setprops (11, pspproparray, & lppropproblemarray); <br/> pmessage-> savechanges (keep_open_readwrite ); </P> <p> pmessage-> setprops (ulpropertycount, lpmailuserpropvaluearray, & lppropproblemarray); </P> <p> pmessage-> savechanges (keep_open_readwrite ); </P> <p> Delete pspproparray; </P> <p> pmessage-> release (); <br/> pmessage = NULL; <br/>}</P> <p> If (pcontactfolder! = NULL) <br/>{< br/> pcontactfolder-> release (); <br/> pcontactfolder = NULL; <br/>}</P> <p> pwabobject-> freebuffer (lpmailuserpropvaluearray ); </P> <p> pmailuser-> release (); <br/> pmailuser = NULL; <br/>}</P> <p> pwabobject-> freebuffer (prowsets2 ); <br/>}</P> <p> pwabobject-> freebuffer (prowsets ); <br/> prowsets = NULL; <br/>}</P> <p> pwabo Bject-> freebuffer (pentryid); <br/>}</P> <p> If (paddrbook! = NULL) <br/>{< br/> paddrbook-> release (); <br/> paddrbook = NULL; <br/>}</P> <p> freelibrary (hinstwab ); <br/>}< br/> catch (cexception * Ex) <br/>{< br/> cutilities: errorlog (Ex); <br/>}< br/> catch (pchar szerror) <br/>{< br/> cutilities: errorlogex (szerror); <br/>}< br/> catch (...) <br/>{< br/>}</P> <p> return hr;

 

Windows Address Book is a component used for Windows XP and Outlook Express. Although it is outdated, there is very little information on the Internet. Share This code snippet, hope to help people who encounter similar problems. :)

 

Refer:

 

Http://blog.csdn.net/terrycgao/archive/2006/06/22/820612.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.