Thread: LDAP access
View Single Post
  #3  
Old December 2nd 08, 05:19 PM posted to microsoft.public.outlook.program_addins
Sergeichik
external usenet poster
 
Posts: 21
Default LDAP access

I have write:

bool ReadAD()
{

// 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;
};

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

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

//The rest is actual code:
SizedSPropTagArray( 1, columns) = { 1, PR_ENTRYID};

SPropValue criteria[ 2];
SRestriction restrictions[ 2];
SRestriction andNode;

criteria[ 0].ulPropTag = PR_AB_PROVIDER_ID;
criteria[ 0].Value.bin.cb = 16;
const BYTE muid[] = MUIDEMSAB;
criteria[ 0].Value.bin.lpb = (BYTE *) muid;
restrictions[ 0].rt = RES_PROPERTY;
restrictions[ 0].res.resProperty.relop = RELOP_EQ;
restrictions[ 0].res.resProperty.ulPropTag = PR_AB_PROVIDER_ID;
restrictions[ 0].res.resProperty.lpProp = &criteria[ 0];

criteria[ 1].ulPropTag = PR_EMS_AB_CONTAINERID;
criteria[ 1].Value.l = 0;
restrictions[ 1].rt = RES_PROPERTY;
restrictions[ 1].res.resProperty.relop = RELOP_EQ;
restrictions[ 1].res.resProperty.ulPropTag = PR_EMS_AB_CONTAINERID;
restrictions[ 1].res.resProperty.lpProp = &criteria[ 1];

andNode.rt = RES_AND;
andNode.res.resAnd.cRes = 2;
andNode.res.resAnd.lpRes = &restrictions[ 0];

LPSRowSet rows = NULL;

if( SUCCEEDED( HrQueryAllRows( hierh_table,
(LPSPropTagArray) &columns, &andNode, NULL, 0, &rows)))
{
if( rows-cRows)
{
int rows_count = rows-cRows;
}
FreeProws( rows);
}

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

MAPIUninitialize();

return true;
}


But rows_count is 0, although Outlook have connected AD with several
contacts in it.

What's wrong ?
Ads