Board index » cppbuilder » ADSI with BUILDER

ADSI with BUILDER


2006-04-04 02:58:12 PM
cppbuilder9
Hello,
I have spent a lot of time trying to make ADSI (active directory) work with Builder but with no result. The best I have done was an "external error" when using ADsGetObject.
I searched in all newsgroups on earth and I have tried every advice. It does not work :(
Thanks for your help ! :)
Jibe
Mail : replace 'noposte' with 'laposte'
I really really need your help ! Does anyone have an simple example of code that works with ADSI ? (I begin thinking it does not exist :'( )
 
 

Re:ADSI with BUILDER

Jibe wrote:
Quote
Hello,

I have spent a lot of time trying to make ADSI (active directory) work with Builder but with no result. The best I have done was an "external error" when using ADsGetObject.

I searched in all newsgroups on earth and I have tried every advice. It does not work :(

Thanks for your help ! :)
To use active directory with BCB you need set of headers from MS
Platform SDK and activeds.lib . Headers you already have and lib file is
integral part of bccSDK. So download and setup bccSDK from
bccsdk.sourceforge.net/.
Also I highly recommend you to download MS Platform SDK because it has
very detailed help together with samples for active directory.
Here is a link for sample below:
tinyurl.com/jyo3t
And here is a link for ADSI on MSDN:
tinyurl.com/5glom
Then you can compile sample like this (taken from platform SDK help and
slightly modified):
//sample.cpp
//---------------------------------------------------------------------------
#include <windows.h>
#include <comdef.h>
#include <activeds.h>
//---------------------------------------------------------------------------
#pragma comment(lib,"activeds.lib")
#pragma comment(lib,"comsupp.lib")
#pragma argsused
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,
reinterpret_cast<void**>(&pCont) );
if ( !SUCCEEDED(hr) )
{
return 0;
}
//-----------------
// Create a user
//-----------------
hr = pCont->Create( _bstr_t("user"),
_bstr_t("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();
return 0;
}
//---------------------------------------------------------------------------
 

Re:ADSI with BUILDER

Darko Miletic wrote:
Quote
To use active directory with BCB you need set of headers from MS
Platform SDK and activeds.lib .
Here I must add you will need adsiid.lib that is also part of bccSDK.
Quote
#pragma comment(lib,"activeds.lib")
#pragma comment(lib,"comsupp.lib")
So we need to add this too:
#pragma comment(lib,"adsiid.lib")
 

{smallsort}

Re:ADSI with BUILDER

Thank you very much for your help. I'll try this tomorow morning ! This is very kind ! I hope it will work :)