Einzelnen Beitrag anzeigen

Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#68

Re: Zugriffsverletzung ADSI, so was komisches hab ich noch n

  Alt 24. Feb 2010, 16:36
I have seen the problem: delphi creates garbage when importing the TypeLib for Active Directory. I reimported the typelib from c:\windows\system32\activeds.tlb with Delphi 2010 and it's still the same mess. The declaration of IDirectorySearch is totally wrong (and the one in AdsHlp.pas is wrong as well).

This works fine for me:

Delphi-Quellcode:
type
  ADS_SEARCH_HANDLE = THandle;
  PADS_SEARCH_HANDLE = ^ADS_SEARCH_HANDLE;
// *********************************************************************//
// Interface: IDirectorySearch
// Flags: (0)
// GUID: {109BA8EC-92F0-11D0-A790-00C04FD8D5A8}
// *********************************************************************//
  IDirectorySearch = interface(IUnknown)
    ['{109BA8EC-92F0-11D0-A790-00C04FD8D5A8}']
    function SetSearchPreference(var pSearchPrefs: ads_searchpref_info; dwNumPrefs: LongWord): HResult; stdcall;
    function ExecuteSearch(pszSearchFilter: PWideChar; pAttributeNames: PWideChar;
                            dwNumberAttributes: LongWord; var phSearchResult: ADS_SEARCH_HANDLE): HResult; stdcall;
    function AbandonSearch(phSearchResult: ADS_SEARCH_HANDLE): HResult; stdcall;
    function GetFirstRow(hSearchResult: ADS_SEARCH_HANDLE): HResult; stdcall;
    function GetNextRow(hSearchResult: ADS_SEARCH_HANDLE): HResult; stdcall;
    function GetPreviousRow(hSearchResult: ADS_SEARCH_HANDLE): HResult; stdcall;
    function GetNextColumnName(hSearchHandle: ADS_SEARCH_HANDLE; out ppszColumnName: PWideChar): HResult; stdcall;
    function GetColumn(hSearchResult: ADS_SEARCH_HANDLE; szColumnName: PWideChar;
                        out pSearchColumn: ads_search_column): HResult; stdcall;
    function FreeColumn(var pSearchColumn: ads_search_column): HResult; stdcall;
    function CloseSearchHandle(hSearchResult: ADS_SEARCH_HANDLE): HResult; stdcall;
  end;

procedure TMainForm.Button1Click(Sender: TObject);
var
  ColCount: DWORD;
  ColNames: array of PWideChar;
  DirSearch: IDirectorySearch;
  SearchHandle: ADS_SEARCH_HANDLE;
  hr : HRESULT;
begin
  ColCount := 1;
  SetLength(ColNames, 3);
  ColNames[0] := 'name';
  ColNames[1] := 'description';
  ColNames[2] := 'adspath';

  hr := ADsGetObject(PWideChar('LDAP://DC=rmi,DC=local'), IID_IDirectorySearch, Pointer(DirSearch));

  if failed(hr) then
    Exit;

  SearchHandle := 0;
  hr := DirSearch.ExecuteSearch('(objectClass=organizationalUnit)', @ColNames[0], Length(ColNames), SearchHandle);
  if failed(hr) then
    Exit;

  while DirSearch.GetNextRow(SearchHandle) <> S_ADS_NOMORE_ROWS do
  begin
    // Do something with result
  end;
  DirSearch.CloseSearchHandle(SearchHandle);
  DirSearch := nil;
end;
See my blog blog
See our Jedi blog
  Mit Zitat antworten Zitat