I'm trying out the sample program below, but it won't link because of unresolved external symbol for both IID_IADs
and IID_IADsContainer
.
What library am I support to include to resolve that?
#include <windows.h>
#include <activeds.h>
#include <comdef.h>
#include <iostream>
#pragma comment(lib, "Activeds.lib")
int main() {
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr)) {
std::cout << "Failed to initialize COM library." << std::endl;
return 1;
}
IADsContainer* pContainer = NULL;
hr = ADsOpenObject(L"LDAP://DC=mydomain,DC=com", NULL, NULL, ADS_SECURE_AUTHENTICATION, IID_IADsContainer, (void**)&pContainer);
if (FAILED(hr)) {
std::cout << "Failed to bind to Active Directory." << std::endl;
CoUninitialize();
return 1;
}
IEnumVARIANT* pEnum = NULL;
hr = ADsBuildEnumerator(pContainer, &pEnum);
if (FAILED(hr)) {
std::cout << "Failed to get enumerator." << std::endl;
pContainer->Release();
CoUninitialize();
return 1;
}
VARIANT var;
ULONG lFetch;
IDispatch* pDispatch = NULL;
IADs* pADs = NULL;
BSTR bstrClass;
while (S_OK == ADsEnumerateNext(pEnum, 1, &var, &lFetch)) {
pDispatch = V_DISPATCH(&var);
hr = pDispatch->QueryInterface(IID_IADs, (void**)&pADs);
if (SUCCEEDED(hr)) {
hr = pADs->get_Class(&bstrClass);
if (SUCCEEDED(hr)) {
if (_wcsicmp(bstrClass, L"computer") == 0) {
BSTR bstrName;
hr = pADs->get_Name(&bstrName);
if (SUCCEEDED(hr)) {
std::wcout << L"Computer: " << bstrName << std::endl;
SysFreeString(bstrName);
}
}
SysFreeString(bstrClass);
}
pADs->Release();
}
VariantClear(&var);
}
ADsFreeEnumerator(pEnum);
pContainer->Release();
CoUninitialize();
return 0;
}
@RemyLebeau pointed out the correct solution, Setting Up the Microsoft Visual C++ 6.0 Development Environment.
- Point to the include and library directory. Select Tools | Options. Click the Directory tab, and specify the path to the ADSI header files.
- Include the Activeds.h file in your project.
- Add the Activeds.lib and Adsiid.lib files to the linker input for your project.