| Platform SDK: Active Directory, ADSI, and Directory Services |
The ADsBuildVarArrayStr function builds a variant array from an array of Unicode strings.
HRESULT ADsBuildVarArrayStr( LPWSTR *lppPathNames, DWORD dwPathNames, VARIANT *pVar );
This method supports the standard return values, as well as the following:
For other return values, see ADSI Error Codes.
To support Automation, use the ADsBuildVarArrayStr function to convert Unicode strings to a variant array of strings. The following code snippet illustrates how to use this function to convert an object's class names from Unicode strings to a variant array of strings.
HRESULT EnumObject(LPWSTR pszADsPath,
LPWSTR * lppClsNames,
DWORD dwClsNames)
{
ULONG ulFetched = 0L;
IEnumVARIANT * pEnumVar = NULL;
VARIANT varFilter, varArray[MAX_ADS_ENUM];
HRESULT hr;
IADsContainer * pADsContainer = NULL;
DWORD dwObjects = 0, dwEnumCount=0, i=0;
BSTR bstrName;
BOOL fContinue=TRUE;
hr = ADsGetObject(pszADsPath,
IID_IADsContainer,
(void**)&pADsContainer);
if (FAILED(hr)) goto cleanup;
//Create a string array of class names as search filters.
VariantInit(&varFilter);
hr = ADsBuildVarArrayStr(lppClsNames, dwClsNames, &varFilter);
if (FAILED(hr)) goto cleanup;
//Apply filters to objects in the container.
hr = pADsContainer->put_Filter(varFilter);
if(FAILED(hr)) goto cleanup;
//Create an enumerator.
hr = ADsBuildEnumerator(pADsContainer, &pEnumVar);
if(FAILED(hr)) goto cleanup;
//Enumerate through the objects and print out their names.
while(fContinue) {
IADs* pObject;
hr = ADsEnumerateNext(pEnumVar, MAX_ADS_ENUM,
varArray, &ulFetched);
if(hr == S_FALSE) fContinue = FALSE;
dwEEnumCount++;
for (i=0; i<ulFetched; i++) {
IDispatch *pDispatch = NULL;
pDispatch = varArray[I].pDispVal;
hr = pDispatch->QueryInterface(IID_IADs,
(void**) &pObject);
if (FAILED(hr)) goto cleanup;
hr = pObject->get_Name(&bstrName);
if(FAILED(hr)) goto cleanup;
printf(" Object name: %S\n",bstrName);
//We are done with the ADSI object.
SysFreeString(bstrname);
pObject->Release();
pDispatch->Release();
}
memset(varArray, 0, sizeof(VARIANT)*MAX_ADS_ENUM);
dwObjects += ulFetched;
}
hr = S_OK;
cleanup:
if(bstrName) SysFreeString(bstrName);
if(pEnumvar) ADsFreeEnumerator(pEnumVar);
if(pADsContainer) pADsContainer->Release();
return (hr);
}
Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
Windows 95/98: Requires Windows 95 or later (with DSClient).
Header: Declared in Adshlp.h.
Library: Included as a resource in ActiveDs.dll.