|
#include "stdafx.h"
#include <lightbox.h>
int main(int argc, char* argv[])
{
char *szServer = "server";
char *szUser = "user";
char *szPassword = "password";
_bstr_t bstrServer("WinNT://");
bstrServer.operator += (szServer);
_bstr_t bstrUser(szUser);
_bstr_t bstrPassword(szPassword);
HRESULT hr;
CoInitialize( NULL );
// コンテナオブジェクトの取得
IADsContainer *pContainer;
hr = ADsOpenObject(
bstrServer.operator wchar_t *(),
bstrUser.operator wchar_t *(),
bstrPassword.operator wchar_t *(),
0x1,
IID_IADsContainer,
(LPVOID*)&pContainer
);
if( FAILED( hr ) ) {
return 0;
}
// コンテナオブジェクトにユーザ用のフィルタを設定
VARIANT varFilter;
LPWSTR pszTarget = {L"user"};
hr = ADsBuildVarArrayStr(
&pszTarget,
1,
&varFilter
);
if( FAILED( hr ) ) {
pContainer->Release();
return 0;
}
hr = pContainer->put_Filter( varFilter );
if( FAILED( hr ) ) {
pContainer->Release();
return 0;
}
// 列挙オブジェクトの取得
IEnumVARIANT *pIEnumVARIANT;
hr = ADsBuildEnumerator(
pContainer,
&pIEnumVARIANT
);
if( FAILED( hr ) ) {
pContainer->Release();
return 0;
}
VARIANT varEnum;
ULONG pcElementsFetched;
IADs *pADs;
CComBSTR bstrTarget;
// コンテナ内のオブジェクト一覧
while( 1 ) {
hr = ADsEnumerateNext(
pIEnumVARIANT,
1,
&varEnum,
&pcElementsFetched
);
if( FAILED( hr ) ) {
break;;
}
if ( pcElementsFetched == 0 ) {
break;
}
hr = ((&varEnum)->pdispVal)->QueryInterface(
IID_IADs,
(LPVOID*)&pADs
);
if( FAILED( hr ) ) {
break;
}
pADs->get_Name( &bstrTarget );
printf( "%S\n", bstrTarget );
pADs->Release();
VariantClear( &varEnum );
}
// 列挙オブジェクトの解放
ADsFreeEnumerator( pIEnumVARIANT );
// コンテナオブジェクトの解放
pContainer->Release();
CoUninitialize();
return 0;
}
| |