Click here to Skip to main content
13,596,723 members
Click here to Skip to main content
Add your own
alternative version


53 bookmarked
Posted 21 Dec 2002

Accessing the Windows Address Book

, 1 Jan 2003
Rate this:
Please Sign up or sign in to vote.
A class to access the WAB


After releasing my first freeware product QuickE numerous request came in, to have the application integrate with the user's address book in their Windows Address Book. On Windows XP, you can find this application by clicking Start->Programs->Accessories->[click] Address Book. I was surprised that anyone was using Windows Address Book, as I was under the naive assumption that everyone uses Outlook or at least Outlook Express (since the latter is at least free), but to my astonishment a lot of people just use the normal Windows Address Book application that comes with most installation of Windows, and if you do use Outlook Express you can actually see that the address book is filled with the same address in Outlook Express. As soon as I started this task, the first thing I did was type in WAB (Windows Address Book) into my MSDN search facility, lo and behold my surprise, at the very small amount of information that was returned to me. I wrote this class in order for other people to have at least a starting point in accessing and using the WAB. I hope you find the source code useful.

System requirements

This code was written and tested in Visual Studio.NET using unmanaged C++ and Win XP Professional. Tony R. tested this code using Visual C++ 6 and was able to get it to run. If anyone else can run this on another platform, let us know so I can post it here, that would be great. Until I get confirmation that this class works in other development environments and on other operating systems, I will list only what I have tested on a first hand basis.

Accessing the WAB

In order to access the WAB you must first load the wab32.dll library and get the address to WAB open which also gives you pointers to the IAdrBook and IWABObject interfaces. Below is a code snippet on how I made this call:

//We're safe the module was initialzised let's do what we need to do
ssWABOpen = (fWABOpen)GetProcAddress(hModule, "WABOpen");
//If not successful throw an error throw the value = 2
if (ssWABOpen == NULL) return 2;
//It is successful call it
HRESULT hr = (ssWABOpen)(&lpAddrBook, &lpWABObject, NULL, 0);

ssWABOpen is a typedef to the WABOpen function. Something I came across when writing this is, finding out that when you typedef this function you must declare the calling mechanism as WINAPI or when compiling you will get a mismatch error.

After this I then call the object's LoadEmails() function. This private function called from within the InitAddrBook function, loads the emails into a UDT of objects within an STL::vector object. I decide to go this route, mainly because of more ignorance on my part, my address book is about 20 names and this method does not soak up too much system resources. If this does not work out for others, I will change it to something more system resource friendly.

Inside the LoadEmails() function is where all the email extraction from the WAB to my UDT vector takes place. You can modify or change this into something that would be more appropriate for your specific use. Or, extract the information into a more useful UDT other than the one I have created.

Usage and special functions

In order to give you a foundation of how to use the class, this is how I use the class in my current beta build of my application. In the main dialog's class I declare a private variable of class CWinAddrBook. I then initialize this variable inside of the dialogs class' OnInitDialog() function, by calling object.InitAddrBook member method. This does two things, first it loads the wab32.dll and then, retrieves from this, the address for the WABOpen() function.

In order to test this class before releasing and not having to build its on application container I created the member method TestAddr(). This basically takes the contents of the vector after you initialized it, and outputs it (TRACE) while running in debug mode to the output window, it then separates the output by carriage line feed pair. This way you are insured that something is actually in your vector and you can look at the output compared to your address book to insure that all the information transferred over correctly.

Request for comments/dilemmas

When creating this class, here are some strange things I came across, maybe someone could shed some light. First thing that caught me off guard is just by using MSDN documents I tried to only include wabapi.h, when in fact it is better to include just wab.h. By going with what is listed on the interface help sections all I saw was WABAPI and for a while I could not get it to compile.

When I first compiled it into my code, I kept getting a

error C2371: 'WCHAR' redfinition; different basic types

inside of wabdefs.h which is included when you specify wab.h. The work around I used was go into this file and around line line 77 I made this change in order to get my code to compile. I do not know why I had to do this or if it is even right, but it worked. If someone knows what this means I would be greatly appreciative of knowing why it does this.

#if !defined(UNIX) && !defined(WIN16) && !defined(WIN32)

LoadEmails() used to be a separate function that was called after InitAddr() however I kept getting an unhandled exception inside the OnInitDialog function. After removing the public function call to LoadEmails, and made it a private function called from within InitAddr() it works fine.


Not MSDN! j/k Most of the contributors are included in the header file comments. I will also include here Hirosh for his article on Extracting Email ID's from an address book using Memory mapped file, and another author is anonymous. I got the code snippet from a friend, who said he found it on the Internet, and I have included it in the download file the way I received it. But if anyone knows the author's name or web address please let me know, so I can give him/her the proper credit.

Tony R. for testing out the code in Visual C++ 6 and finding numerous other bugs.


  • 1/2/2003: Updated code and changed the extraction process to extract information into separate areas instead of repeatedly extracting all address information to the name field. Changed the structure that holds addresses to use basic_string instead of a fixed sized array of characters to avoid buffer overrun problems I was experiencing.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
My real name is Sam I live in Monterey, California. I am currently unemployed - long story. I am trying to secure a job as a programmer in the Silicon Valley area of CA but so far no luck. Now with all this extra time I am writing code and learning concepts I have put off because I was too busy working Smile | :)

I have completed two of my programming goals: release software in the form of freeware, and write an article for CodeProject!

You may also be interested in...

Comments and Discussions

QuestionHow to add new contact to Address Book by code? Pin
sunooo15-Nov-06 20:26
membersunooo15-Nov-06 20:26 
Generalidentities Pin
kirans462-Aug-06 0:17
memberkirans462-Aug-06 0:17 
QuestionHow get all new contacts which are created after a given time? Pin
mpprasad22-Jul-06 20:51
membermpprasad22-Jul-06 20:51 
QuestionHow to get creation time of a VCard or contact Pin
mpprasad6-Jul-06 20:22
membermpprasad6-Jul-06 20:22 
QuestionHow to create folder in Windows Address Book in code? Pin
simon.lm5-Jun-06 16:41
membersimon.lm5-Jun-06 16:41 
GeneralSolving the "error C2371: 'WCHAR' redefinition..." mystery. Pin
Julberto Danray21-Apr-06 18:32
memberJulberto Danray21-Apr-06 18:32 
QuestionHow to get more infomation of mailuser? Pin
pesalo5-Feb-06 22:44
memberpesalo5-Feb-06 22:44 
GeneralWhy is Incorrect TimeValue returned from API Pin
Douglas R. Keesler30-May-05 6:52
memberDouglas R. Keesler30-May-05 6:52 
GeneralRe: Why is Incorrect TimeValue returned from API Pin
Puddin Tame31-Aug-05 16:04
memberPuddin Tame31-Aug-05 16:04 
GeneralWCHAR solution Pin
Anonymous10-Mar-05 21:04
sussAnonymous10-Mar-05 21:04 
QuestionAccess violation? Pin
MaggieLuo2-Dec-04 4:01
memberMaggieLuo2-Dec-04 4:01 
AnswerRe: Access violation? Pin
MaggieLuo2-Dec-04 15:13
memberMaggieLuo2-Dec-04 15:13 
GeneralRe: Access violation? Pin
ctype15-Jan-08 4:04
memberctype15-Jan-08 4:04 
GeneralPlease how to get the Emails from wab using c# Pin
Angel Tsvetkov22-Nov-04 0:56
memberAngel Tsvetkov22-Nov-04 0:56 
QuestionHow Can I get the Email Address with C# Pin
liyang (China)27-May-04 18:22
memberliyang (China)27-May-04 18:22 
AnswerRe: How Can I get the Email Address with C# Pin
yangguotai29-Apr-10 22:14
memberyangguotai29-Apr-10 22:14 
QuestionHow to add new contact to Address Book by code? Pin
HuuQuynh17-May-04 22:33
memberHuuQuynh17-May-04 22:33 
AnswerRe: How to add new contact to Address Book by code? Pin
Maia20-May-04 5:57
memberMaia20-May-04 5:57 
GeneralRe: How to add new contact to Address Book by code? Pin
DAenil12-Jul-04 1:00
sussDAenil12-Jul-04 1:00 
GeneralRe: How to add new contact to Address Book by code? Pin
SPartha30-Aug-04 8:24
memberSPartha30-Aug-04 8:24 
GeneralRe: How to add new contact to Address Book by code? Pin
Ashish Chauhan3-Apr-05 23:31
sussAshish Chauhan3-Apr-05 23:31 
QuestionRe: How to add new contact to Address Book by code? Pin
Rustam_Rustamov5-Sep-06 8:49
memberRustam_Rustamov5-Sep-06 8:49 
GeneralBugs Pin
Vattila13-Sep-03 12:56
memberVattila13-Sep-03 12:56 
GeneralRe: Bugs Pin
Vattila23-Sep-03 8:34
memberVattila23-Sep-03 8:34 
GeneralRe: Bugs Pin
kido9715-Dec-04 21:30
memberkido9715-Dec-04 21:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.180621.3 | Last Updated 2 Jan 2003
Article Copyright 2002 by Code4Food
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid