WindowsXP-SP1/ds/adsi/nwnds/cusers.cxx
2020-09-30 16:53:49 +02:00

207 lines
4.0 KiB
C++

//---------------------------------------------------------------------------
//
// Microsoft Windows
// Copyright (C) Microsoft Corporation, 1992 - 1995
//
// File: cUser.cxx
//
// Contents: User object
//
// History: 11-1-95 krishnag Created.
//
//----------------------------------------------------------------------------
#include "procs.hxx"
#pragma hdrstop
#include "nds.hxx"
// Class CNDSUserCollection
DEFINE_IDispatch_Implementation(CNDSUserCollection)
CNDSUserCollection::CNDSUserCollection():
_ADsPath(NULL),
_pDispMgr(NULL)
{
VariantInit(&_vMembers);
VariantInit(&_vFilter);
ENLIST_TRACKING(CNDSUserCollection);
}
HRESULT
CNDSUserCollection::CreateUserCollection(
BSTR bstrADsPath,
VARIANT varMembers,
REFIID riid,
void **ppvObj
)
{
CNDSUserCollection FAR * pUser = NULL;
HRESULT hr = S_OK;
hr = AllocateUserCollectionObject(&pUser);
BAIL_ON_FAILURE(hr);
hr = ADsAllocString(bstrADsPath, &(pUser->_ADsPath));
BAIL_ON_FAILURE(hr);
hr = VariantCopy(&(pUser->_vMembers), &varMembers);
BAIL_ON_FAILURE(hr);
hr = pUser->QueryInterface(riid, ppvObj);
BAIL_ON_FAILURE(hr);
pUser->Release();
RRETURN(hr);
error:
delete pUser;
RRETURN(hr);
}
CNDSUserCollection::~CNDSUserCollection( )
{
VariantClear(&_vMembers);
VariantClear(&_vFilter);
delete _pDispMgr;
}
STDMETHODIMP
CNDSUserCollection::QueryInterface(
REFIID iid,
LPVOID FAR* ppv
)
{
if (ppv == NULL) {
RRETURN(E_POINTER);
}
if (IsEqualIID(iid, IID_IUnknown))
{
*ppv = (IADsMembers FAR *) this;
}
else if (IsEqualIID(iid, IID_IADsMembers))
{
*ppv = (IADsMembers FAR *) this;
}
else if (IsEqualIID(iid, IID_IDispatch))
{
*ppv = (IADsMembers FAR *) this;
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return NOERROR;
}
STDMETHODIMP
CNDSUserCollection::get_Count(long FAR* retval)
{
RRETURN(E_NOTIMPL);
}
STDMETHODIMP
CNDSUserCollection::get_Filter(THIS_ VARIANT FAR* pVar)
{
VariantInit(pVar);
RRETURN(VariantCopy(pVar, &_vFilter));
}
STDMETHODIMP
CNDSUserCollection::put_Filter(THIS_ VARIANT Var)
{
VariantClear(&_vFilter);
RRETURN(VariantCopy(&_vFilter, &Var));
}
STDMETHODIMP
CNDSUserCollection::get__NewEnum(
THIS_ IUnknown * FAR* retval
)
{
HRESULT hr;
IUnknown FAR* punkEnum=NULL;
IEnumVARIANT * penum = NULL;
*retval = NULL;
hr = CNDSUserCollectionEnum::Create(
_ADsPath,
(CNDSUserCollectionEnum **)&penum,
_vMembers,
_Credentials
);
BAIL_ON_FAILURE(hr);
hr = penum->QueryInterface(
IID_IUnknown,
(VOID FAR* FAR*)retval
);
BAIL_ON_FAILURE(hr);
if (penum) {
penum->Release();
}
RRETURN(NOERROR);
error:
if (penum) {
delete penum;
}
RRETURN(hr);
}
HRESULT
CNDSUserCollection::AllocateUserCollectionObject(
CNDSUserCollection ** ppUser
)
{
CNDSUserCollection FAR * pUser = NULL;
CDispatchMgr FAR * pDispMgr = NULL;
HRESULT hr = S_OK;
pUser = new CNDSUserCollection();
if (pUser == NULL) {
hr = E_OUTOFMEMORY;
}
BAIL_ON_FAILURE(hr);
pDispMgr = new CDispatchMgr;
if (pDispMgr == NULL) {
hr = E_OUTOFMEMORY;
}
BAIL_ON_FAILURE(hr);
hr = LoadTypeInfoEntry(pDispMgr,
LIBID_ADs,
IID_IADsMembers,
(IADsMembers *)pUser,
DISPID_NEWENUM
);
BAIL_ON_FAILURE(hr);
pUser->_pDispMgr = pDispMgr;
*ppUser = pUser;
RRETURN(hr);
error:
delete pDispMgr;
RRETURN(hr);
}