当前位置: 首页>>代码示例>>C++>>正文


C++ IADs::QueryInterface方法代码示例

本文整理汇总了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;
}
开发者ID:cpm2710,项目名称:cellbank,代码行数:56,代码来源:HelperUtilTest.cpp

示例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);
//.........这里部分代码省略.........
开发者ID:AbdoSalem95,项目名称:WindowsSDK7-Samples,代码行数:101,代码来源:Credentials.cpp


注:本文中的IADs::QueryInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。