Directory Services |
Setting Up the Microsoft Visual C++ 6.0 Development Environment
Microsoft® Visual C++ 6.0 can be used to develop enterprise applications. To set up your Visual C++ 6.0 environment to develop an ADSI application, perform the following steps:
A Sample Visual C++ Application: Creating a User in a Domain
Log on to a Windows 2000 or Windows Server 2003 domain. You must also have permission to modify data in Active Directory. By default, the Administrator has this privilege. To enter this code example:
#include "stdafx.h" #include "activeds.h" int main(int argc, char* argv[]) { HRESULT hr; IADsContainer *pCont; IDispatch *pDisp=NULL; IADs *pUser; // Initialize COM before calling any ADSI functions or interfaces. CoInitialize(NULL); hr = ADsGetObject( L"LDAP://CN=users,DC=fabrikam,DC=com", IID_IADsContainer, (void**) &pCont ); if ( !SUCCEEDED(hr) ) { return 0; } //----------------- // Create a user //----------------- hr = pCont->Create(CComBSTR("user"), CComBSTR("jeffsmith"), &pDisp ); // Release the container object. pCont->Release(); if ( !SUCCEEDED(hr) ) { return 0; } hr = pDisp->QueryInterface( IID_IADs, (void**) &pUser ); // Release the dispatch interface. pDisp->Release(); if ( !SUCCEEDED(hr) ) { return 0; } // Commit the object data to the directory. pUser->SetInfo(); // Release the object. pUser->Release(); CoUninitialize(); }