RE: IDsObjectPicker AttributesToFetch mystery
- From: Franky@xxxxxxxx <Frankyhomecom@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 13 Jun 2005 06:32:02 -0700
I recently stumbled on the problem myself.
here you have a basic example in C++ of how to get additional attributes
The important points here are :
Create an array of pointers to unicode string each containing the attribute
name you wish to retrieve.Be sure to get the names right! If unsure write a
quick program to dump all the attributenames for a given object for instance
"user" using
IDsDisplaySpecifier->GetAttributeADsType.
Next invoke the dialog
On return pvarFetchedAttributes holds an array of variants in the same order
as the attributenames directory. If the attribute does not exist the type of
the variant=VT_EMPTY
Hope it helps.
HRESULT hr;
IDsObjectPicker *pDsObjectPicker = NULL;
IDataObject *pdo = NULL;
hr =
CoCreateInstance(CLSID_DsObjectPicker,NULL,CLSCTX_INPROC_SERVER,IID_IDsObjectPicker,reinterpret_cast<LPVOID*>(&pDsObjectPicker));
if(SUCCEEDED(hr))
{
DSOP_SCOPE_INIT_INFO aScopeInit[1];
DSOP_INIT_INFO InitInfo;
PCWSTR AttributeNames[2];
WCHAR m_AccountName[30];
WCHAR m_displayName[30];
//Initialise Scope
ZeroMemory(aScopeInit, sizeof(aScopeInit));
aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
aScopeInit[0].flType = DSOP_SCOPE_TYPE_TARGET_COMPUTER
| DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
| DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN;
//Initialize Filter
aScopeInit[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_USERS;
aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_USERS;
//Initialze array of attributes to retrieve
STR2UNI(m_AccountName,"samAccountName");
STR2UNI(m_displayName,"displayName");
AttributeNames[0]=m_AccountName;
AttributeNames[1]=m_displayName;
ZeroMemory(&InitInfo, sizeof(InitInfo));
InitInfo.cbSize = sizeof(InitInfo);
InitInfo.pwzTargetComputer = NULL;
InitInfo.cDsScopeInfos = sizeof(aScopeInit)/sizeof(DSOP_SCOPE_INIT_INFO);
InitInfo.aDsScopeInfos = aScopeInit;
InitInfo.flOptions = DSOP_FLAG_MULTISELECT;
InitInfo.cAttributesToFetch=2;
InitInfo.apwzAttributeNames=reinterpret_cast<PCWSTR*>(&AttributeNames);
hr=pDsObjectPicker->Initialize(&InitInfo);
if(SUCCEEDED(hr))
{
hr=pDsObjectPicker->InvokeDialog(this->m_hWnd, &pdo);
if (hr == S_OK)
{
STGMEDIUM stm;
FORMATETC fe;
fe.cfFormat = RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
fe.ptd = NULL;
fe.dwAspect = DVASPECT_CONTENT;
fe.lindex = -1;
fe.tymed = TYMED_HGLOBAL;
hr = pdo->GetData(&fe, &stm);
if(SUCCEEDED(hr))
{
PDS_SELECTION_LIST pDsSelList = NULL;
pDsSelList = (PDS_SELECTION_LIST)GlobalLock(stm.hGlobal);
if(NULL != pDsSelList)
{
for(ULONG i = 0; i < pDsSelList->cItems; i++)
{
CString m_UserId,m_DisplayName;
if(pDsSelList->aDsSelection[i].pvarFetchedAttributes[0].vt!=VT_EMPTY)
m_UserId=pDsSelList->aDsSelection[i].pvarFetchedAttributes[0].bstrVal;
if(pDsSelList->aDsSelection[i].pvarFetchedAttributes[1].vt!=VT_EMPTY)
m_DisplayName=pDsSelList->aDsSelection[i].pvarFetchedAttributes[1].bstrVal;
}
}
GlobalUnlock(stm.hGlobal);
}
pdo->Release();
}
}
pDsObjectPicker->Release();
}
"CAJazzMan" wrote:
> Has ANYONE been successful in impementing the ObjectPicker dialog and getting
> additional attributes? I as well as a lot of other people around the net are
> trying to retrieve the objectSID from this call. I am using c# + Interop and
> have been successful only when no additional attributes are requested. Thank
> you very much for any advise here.
>
.
- Prev by Date: how to manage user between child and parent domain ???
- Next by Date: Roaming profile trouble - please help me !!!!
- Previous by thread: how to manage user between child and parent domain ???
- Next by thread: Roaming profile trouble - please help me !!!!
- Index(es):
Relevant Pages
|