Hi

A tool of mine would like to find out which Active Directory
folder/path a computer account can be found in.

I thought using the IDirectorySearch object would work but
as i wouldn't like to introduce C++ overhead i would like to
use the class from C via the vtab pointers to functions.

However, even if the "autocomplete" (i forgot it's correct name) feature
of MSVC++.NET 2002 does help me write the code, the compiler
complains about the function pointers not being defined.

Here is the routine (excluding some cleanup code used on error):

BOOL bGetADPathOfPC(char *p_szPCname, char *p_szResult)
{
int i;
IDirectorySearch *p_DS;
ADS_SEARCH_HANDLE hADS;
ADS_SEARCH_COLUMN col;
char szQuery[1000];
WCHAR wszQuery[1000];

CoInitialize(NULL);
if (ADsOpenObject(L"WinNT://ourDomainName/Workstations", NULL, NULL,
ADS_READONLY_SERVER, IID_IDirectorySearch, (void **) &p_DS)==S_OK)
return FALSE;
i=sprintf(szQuery, "(Computer=%s)", g_szPCname);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szQuery, i+1, wszQuery,
sizeof(wszQuery)/sizeof(wszQuery[0]));
if (S_OK != (p_DS->ExecuteSearch(wszQuery, L"ADsPath", 1, &hADS))
|| S_OK != p_DS->GetFirstRow(hADS) ||
S_OK != p_DS->GetColumn(hADS, L"ADsPath", &col)) return FALSE;
if (col.dwADsType!=ADSTYPE_CASE_IGNORE_STRING) return FALSE;
WideCharToMultiByte(CP_ACP, MB_PRECOMPOSED,
col.pADsValues->CaseIgnoreString, -1, p_szResult, 999, NULL, NULL);
return TRUE;
}

The errors i get is...
.....\Routines.c(237) : error C2039: 'ExecuteSearch' : is not a member of
'IDirectorySearch'
c:\Program FilesMicrosoft Visual Studio
..NET\Vc7\PlatformSDK\Include\Iads.h(17561) : see declaration of
'IDirectorySearch'

At line 17561 in Iads.h i find...
interface IDirectorySearch
{
CONST_VTBL struct IDirectorySearchVtbl *lpVtbl;
};
.... which doesn't seem very C-like.

Is this supposed to work somehow from pure C and if so
then what am i missing?
And would code like this actually be able to get the path of
a Computer account in the Active Directory? If not, what
should i use (with C)?

I would apreaciate it if you could help me construct a working
routine before sunday evening so i don't have to leave out a
useful feature on tool delivery on monday 16th. Thanks.

- Sten