Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C++

Accessing the Windows Address Book

Rate me:
Please Sign up or sign in to vote.
4.69/5 (25 votes)
1 Jan 20035 min read 229.1K   2.4K   53  
A class to access the WAB
// CWinAddrBook
//
// Created on: 12/22/2002 
// Written by Sam C
//
// Contributors Source code I found on the web don't know where, but I have included the full source in the ZIP and if
//				anyone knows the author please let me know, Hirosh from CodeProject and his article entitled "Extracting Email ID's from an address book using Memory mapped file"
//
// License: I grant anyone the right to use or distribute this source code for personal or commercial purposes. The only restriction
// is that you must keep the comments at top (the comment file you are reading now) intact, and no changes made to them whatsoever
//
// Copyright 2002 Stuffsoft
// http://www.stuffsoft.com info@stuffsoft.com
//

#pragma once

#include <wab.h>
#include <vector>
#include <string>

using namespace std;

//Typedef the function pointer to WABOpen
typedef HRESULT (WINAPI *fWABOpen)( 
	LPADRBOOK* ,
    LPWABOBJECT* ,
    LPWAB_PARAM ,
    DWORD 
);

typedef struct __EMAILS {
	string DisplayName; //char DisplayName[200];
	string NickName; //char NickName[200];
	string EmailAddr; //char EmailAddr[200];
} EMAILS, *LPEMAILS;

class CWinAddrBook
{
public:
	CWinAddrBook(void);
	~CWinAddrBook(void);
	// Module to library that is opened
	char PathToWAB[255];
	//If hModule is NULL then the library is not loaded yet
	HMODULE hModule;
	// Initialize the address book and load the values into memory (I hope) Return 0 if successful, anything else failed
	int InitAddrBook(void);
	vector<EMAILS> AddrMemBook;	

private:
	// Pointer to the IAddressBook interface
	LPADRBOOK lpAddrBook;
	//Pointer to the WAB object itself that we are using
	LPWABOBJECT lpWABObject;
	// Pointer to the function inside of the wab32.dll for the open procedure
	fWABOpen ssWABOpen;
	// Load email addresses into the vector
	int LoadEmails(void);	

public:
	// Test mostly for debug purposes so you can step through and ensure that all the information is present for the address book vector
	void TestAddrBook(void);
	// Tells if the class has already been initialized or it has not been initialized
	bool IsInit;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
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!

Comments and Discussions