Directory Services

Getting ADSI Interfaces From Your Extension

An extension often needs to get data from the directory object it binds to. For example, an extension for computer may want to get the dnsHostName of the current object from the directory. This can be easily achieved by issuing a QueryInterface call on the IUnknown interface for the aggregator.

HRESULT hr;
IADs *pADs; ' ADSI Interface to get/set attributes.
 
hr = m_pOuterUnk->QueryInterface(IID_IADs,(void**)&pADs);
 
if ( SUCCEEDED(hr) )
{
	VARIANT var;
	VariantInit(&var);
	hr  = pADs ->Get(_bstr_t("dnsHostName"), &var);
	if ( SUCCEEDED(hr) )
	{   
		printf("%S\n", V_BSTR(&var));
}
	VariantClear(&var);
	pADs->Release();
}

You should release the interface immediately after using it. If the extension has an open reference to the aggregator, you have created a circular reference and the aggregator cannot release the extension. Therefore, the aggregator cannot be released and the result is memory leaks in your application.