本文整理汇总了C++中IADs::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ IADs::QueryInterface方法的具体用法?C++ IADs::QueryInterface怎么用?C++ IADs::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IADs
的用法示例。
在下文中一共展示了IADs::QueryInterface方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintAllObjects
HRESULT PrintAllObjects(IADsContainer* pContainer)
{
HRESULT hr;
if(NULL == pContainer)
{
return E_INVALIDARG;
}
IEnumVARIANT *pEnum = NULL;
// Create an enumerator object in the container.
hr = ADsBuildEnumerator(pContainer, &pEnum);
if(SUCCEEDED(hr))
{
VARIANT var;
ULONG ulFetched = 0L;
// Get the next contained object.
while(S_OK == (hr = ADsEnumerateNext(pEnum, 1, &var, &ulFetched)) && (ulFetched > 0))
{
IADs *pADs;
// Print the object
hr = V_DISPATCH(&var)->QueryInterface(IID_IADs, (void**)&pADs);
if(SUCCEEDED(hr))
{
CComBSTR sbstr;
IADsContainer *pChildContainer;
hr = pADs->get_Name(&sbstr);
if(SUCCEEDED(hr))
{
wprintf(sbstr);
wprintf(L"\n");
}
hr = pADs->QueryInterface(IID_IADsContainer, (void**)&pChildContainer);
if(SUCCEEDED(hr))
{
// If the retrieved object is a container, recursively print its contents as well.
PrintAllObjects(pChildContainer);
}
pADs->Release();
}
// Release the VARIANT.
VariantClear(&var);
}
ADsFreeEnumerator(pEnum);
}
return hr;
}
示例2: main
int main(int argc, char* argv[])
{
IADs *pNS = NULL,
*pRoot=NULL,
*pAuth=NULL;
IADsOpenDSObject *pDSObj=NULL;
VARIANT varDSRoot;
TCHAR adspath[MAX_PATH],username[255],password[255];
HRESULT hr;
hr = CoInitialize(NULL);
// Get the name of the root container for this domain.
// Read the Root DSE from the default DS, which will be the DS for
// the local domain. This will get us the name of the schema container,
// which is stored in the "defaultNamingContext" operational attribute.
hr = ADsGetObject(TEXT("LDAP://RootDSE"),
IID_IADs,
(void**)&pRoot);
if ( FAILED(hr) )
{
::CoUninitialize();
_tprintf(TEXT("\nError in ADsGetObject"));
return 1;
}
hr = pRoot->Get(TEXT("defaultNamingContext"),&varDSRoot);
if ( FAILED(hr) )
{
::CoUninitialize();
pRoot->Release();
_tprintf(TEXT("\nError in reading defaultNamingContext"));
return 1;
}
_tprintf(TEXT("\nDomain Name is :%s\n"),varDSRoot.bstrVal);
pRoot->Release();
_tcscpy_s(adspath,MAX_PATH, TEXT("LDAP://"));
// get the remaining buffer size; make sure it copies, avoid buffer overrun
int rem = (sizeof(adspath)/sizeof(TCHAR)) - _tcslen(adspath) -1; //-1 is for NULL
int len = wcslen(varDSRoot.bstrVal);
if ( rem >= len )
{
_tcsncat_s(adspath,MAX_PATH,varDSRoot.bstrVal, len);
}
else
{
pRoot->Release();
VariantClear(&varDSRoot);
return 1;
}
hr = ADsGetObject(TEXT("LDAP:"),
IID_IADs,
(void**)&pNS);
if ( FAILED(hr) )
{
::CoUninitialize();
_tprintf(TEXT("\nError in ADsGetObject"));
return 1;
}
hr = pNS->QueryInterface(IID_IADsOpenDSObject,(void**)&pDSObj);
if ( FAILED(hr) )
{
::CoUninitialize();
pNS->Release();
_tprintf(TEXT("\nError in QueryInterface"));
return 1;
}
//
// Collect the username and password and bind to the Domain using these.
//
if SUCCEEDED(hr)
{
pNS->Release();
_tprintf(TEXT("\nusername:"));
_fgetts(username,sizeof(username)/sizeof(TCHAR),stdin);
username[_tcslen(username)-1] = '\0';
_tprintf(TEXT("\"%s\""), username);
_tprintf(TEXT("\npassword:"));
_fgetts(password, sizeof(password)/sizeof(TCHAR), stdin);
password[_tcslen(password)-1] = '\0';
hr = pDSObj->OpenDSObject(adspath,username,password,ADS_SECURE_AUTHENTICATION,(IDispatch**)&pAuth);
//.........这里部分代码省略.........