Platform SDK: Active Directory, ADSI, and Directory Services |
An extension often needs to get information 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.
Example:
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(L"dnsHostName", &var); printf("%S\n", V_BSTR(&var)); VariantClear(&var); pADs->Release(); }
You should release the interface immediately after using it. Notice the call to pADs->Release in the code above. 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 will be memory leaks in your application.