A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Outlook address books reading (C++).



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 5th 08, 11:07 AM posted to microsoft.public.outlook.program_addins
Sergeichik
external usenet poster
 
Posts: 21
Default Outlook address books reading (C++).

There are at least 2 types of address books in Outlook: 'MAPI' and 'LDAP'.
I try to read all of it by the following working code:

///////////////////////////////////////
bool ReadAddressBooks()
{

// Initialize MAPI.
HRESULT hRes = S_OK;

if (FAILED(hRes = MAPIInitialize(NULL)))
{
return false;
}

HRESULT hr;
LPMAPISESSION pSess;
hr = MAPILogonEx(0, NULL, NULL, MAPI_EXTENDED, &pSess);
if(FAILED(hr))
{
MAPIUninitialize();
return false;
}


// open address book
LPADRBOOK pAddr;
hr = pSess-OpenAddressBook(0, 0, 0, &pAddr);
if(FAILED(hr))
{
pSess-Logoff(0, 0, 0);
MAPIUninitialize();
return false;
};

ULONG obj_type;

// open root container by passing a NULL entry ID
LPMAPICONTAINER rootContainer = NULL;
hr = pAddr-OpenEntry( 0, NULL, NULL, 0, &obj_type,
(LPUNKNOWN*)&rootContainer);

//Get hierarchy table
LPMAPITABLE root_hierh_table, hierh_table;
hr = rootContainer-GetHierarchyTable(0, &root_hierh_table);

// columns
SizedSPropTagArray( 2, columns) = { 2, PR_ENTRYID, PR_DISPLAY_NAME};


LPSRowSet rows = NULL;

//if( SUCCEEDED( HrQueryAllRows( hierh_table,
// (LPSPropTagArray) &columns, &andNode, NULL, 0, &rows)))
if( SUCCEEDED( HrQueryAllRows( root_hierh_table,
(LPSPropTagArray) &columns, NULL, NULL, 0, &rows)))
{
if( rows-cRows)
{
int rows_count = rows-cRows;
for (int row_number = 0; row_number rows_count; row_number++)
{
LPMAPICONTAINER mapiContainer = NULL;
LPMAPITABLE lpContenTstable = NULL;
ULONG objectType = 0;

LPSPropValue lpDN_contN =
PpropFindProp(rows-aRow[ row_number].lpProps,rows-aRow[
row_number].cValues,PR_DISPLAY_NAME);

CString Cont_Name = lpDN_contN-Value.lpszW;

LPSPropValue lpDN_cont =
PpropFindProp(rows-aRow[ row_number].lpProps,rows-aRow[
row_number].cValues,PR_ENTRYID);

_PV* ContainerEntryId = NULL;
ContainerEntryId = &lpDN_cont-Value;
if (!ContainerEntryId)
{ continue;};

// open container
HRESULT hResult = pSess-OpenEntry(ContainerEntryId-bin.cb,
(LPENTRYID)ContainerEntryId-bin.lpb,
NULL, MAPI_BEST_ACCESS, &objectType, (LPUNKNOWN *) &mapiContainer);

if( FAILED( hResult))
{
continue;
}

ULONG ulFlags = NULL;
lpContenTstable = NULL;
hr = mapiContainer-GetContentsTable(ulFlags, &lpContenTstable);
if (hr!=S_OK)
{
}

hierh_table = NULL;
hr = mapiContainer-GetHierarchyTable(0, &hierh_table);

ULONG ulRows; //Number of rows in the MAPI table

ulRows = 0;
if (lpContenTstable)
hr = lpContenTstable-GetRowCount(0, &ulRows);

ulRows = 0;
if (hierh_table)
hr = hierh_table-GetRowCount(0, &ulRows);

if (hierh_table) hierh_table-Release();
if (lpContenTstable) lpContenTstable-Release();
if (mapiContainer) mapiContainer-Release();
} //for all rows (containers)
}// if rows count 0
FreeProws( rows);
}//HrQueryAllRows

if (root_hierh_table) root_hierh_table-Release();
if (rootContainer) rootContainer-Release();
if (pAddr) pAddr-Release();
if (pSess) pSess-Release();

MAPIUninitialize();
return true;
}
///////////////////////////////////////////////////////////////////////////////////


In 'Cont_Name' I have sequentially receiving 2 names of address books:
- 'Outlook address book' (standart)
- 'name of my LDAP address book'

Then I receive valid number of folders in 'Outlook address book' and all
contacts in they (not in this code).
This part is working good.

And I can't receive any item in 'Hierarchy' or 'Contents' tables of 'LDAP
address book'.
Received contained items count is 0 (zero) in both cases.
Why ?
How can I read 'LDAP'-type Outlook address book contents programmatically ?
My 'LDAP'-connection contain several contacts, sure !
And I see them in Outlook.
Ads
  #2  
Old December 5th 08, 04:48 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Outlook address books reading (C++).

LDAP address book provider does not display anythign in the contents table,
it only lets you search and displays the search results.
You can onserver this behavior in the Outlook UI.
This has to do with the fact that very few LDAP servers supports windowing
extensions (that allow to retrieve only a subset of entries) and retrieving
a large number (thousands) of entries is very expensive.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Sergeichik" wrote in message
...
There are at least 2 types of address books in Outlook: 'MAPI' and
'LDAP'.
I try to read all of it by the following working code:

///////////////////////////////////////
bool ReadAddressBooks()
{

// Initialize MAPI.
HRESULT hRes = S_OK;

if (FAILED(hRes = MAPIInitialize(NULL)))
{
return false;
}

HRESULT hr;
LPMAPISESSION pSess;
hr = MAPILogonEx(0, NULL, NULL, MAPI_EXTENDED, &pSess);
if(FAILED(hr))
{
MAPIUninitialize();
return false;
}


// open address book
LPADRBOOK pAddr;
hr = pSess-OpenAddressBook(0, 0, 0, &pAddr);
if(FAILED(hr))
{
pSess-Logoff(0, 0, 0);
MAPIUninitialize();
return false;
};

ULONG obj_type;

// open root container by passing a NULL entry ID
LPMAPICONTAINER rootContainer = NULL;
hr = pAddr-OpenEntry( 0, NULL, NULL, 0, &obj_type,
(LPUNKNOWN*)&rootContainer);

//Get hierarchy table
LPMAPITABLE root_hierh_table, hierh_table;
hr = rootContainer-GetHierarchyTable(0, &root_hierh_table);

// columns
SizedSPropTagArray( 2, columns) = { 2, PR_ENTRYID, PR_DISPLAY_NAME};


LPSRowSet rows = NULL;

//if( SUCCEEDED( HrQueryAllRows( hierh_table,
// (LPSPropTagArray) &columns, &andNode, NULL, 0, &rows)))
if( SUCCEEDED( HrQueryAllRows( root_hierh_table,
(LPSPropTagArray) &columns, NULL, NULL, 0, &rows)))
{
if( rows-cRows)
{
int rows_count = rows-cRows;
for (int row_number = 0; row_number rows_count; row_number++)
{
LPMAPICONTAINER mapiContainer = NULL;
LPMAPITABLE lpContenTstable = NULL;
ULONG objectType = 0;

LPSPropValue lpDN_contN =
PpropFindProp(rows-aRow[ row_number].lpProps,rows-aRow[
row_number].cValues,PR_DISPLAY_NAME);

CString Cont_Name = lpDN_contN-Value.lpszW;

LPSPropValue lpDN_cont =
PpropFindProp(rows-aRow[ row_number].lpProps,rows-aRow[
row_number].cValues,PR_ENTRYID);

_PV* ContainerEntryId = NULL;
ContainerEntryId = &lpDN_cont-Value;
if (!ContainerEntryId)
{ continue;};

// open container
HRESULT hResult = pSess-OpenEntry(ContainerEntryId-bin.cb,
(LPENTRYID)ContainerEntryId-bin.lpb,
NULL, MAPI_BEST_ACCESS, &objectType, (LPUNKNOWN *) &mapiContainer);

if( FAILED( hResult))
{
continue;
}

ULONG ulFlags = NULL;
lpContenTstable = NULL;
hr = mapiContainer-GetContentsTable(ulFlags, &lpContenTstable);
if (hr!=S_OK)
{
}

hierh_table = NULL;
hr = mapiContainer-GetHierarchyTable(0, &hierh_table);

ULONG ulRows; //Number of rows in the MAPI table

ulRows = 0;
if (lpContenTstable)
hr = lpContenTstable-GetRowCount(0, &ulRows);

ulRows = 0;
if (hierh_table)
hr = hierh_table-GetRowCount(0, &ulRows);

if (hierh_table) hierh_table-Release();
if (lpContenTstable) lpContenTstable-Release();
if (mapiContainer) mapiContainer-Release();
} //for all rows (containers)
}// if rows count 0
FreeProws( rows);
}//HrQueryAllRows

if (root_hierh_table) root_hierh_table-Release();
if (rootContainer) rootContainer-Release();
if (pAddr) pAddr-Release();
if (pSess) pSess-Release();

MAPIUninitialize();
return true;
}
///////////////////////////////////////////////////////////////////////////////////


In 'Cont_Name' I have sequentially receiving 2 names of address books:
- 'Outlook address book' (standart)
- 'name of my LDAP address book'

Then I receive valid number of folders in 'Outlook address book' and all
contacts in they (not in this code).
This part is working good.

And I can't receive any item in 'Hierarchy' or 'Contents' tables of 'LDAP
address book'.
Received contained items count is 0 (zero) in both cases.
Why ?
How can I read 'LDAP'-type Outlook address book contents programmatically
?
My 'LDAP'-connection contain several contacts, sure !
And I see them in Outlook.



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I combine Outlook address books? Cindi Outlook - Using Contacts 1 October 29th 08 09:57 PM
address books in Outlook John Outlook - Using Contacts 2 October 12th 08 07:30 AM
How Many Address Books Does Outlook Have? Daddy Outlook - General Queries 6 April 2nd 08 02:44 AM
Merge all address books into the master email address book Denise Outlook - Using Contacts 1 April 11th 07 10:27 PM
Outlook Address Books R. Skilton Outlook - General Queries 1 June 2nd 06 02:34 PM


All times are GMT +1. The time now is 08:56 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.