Einzelnen Beitrag anzeigen

Benutzerbild von Remko
Remko

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

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

  Alt 24. Feb 2010, 16:56
Some more observations: the attribute names in pAttributeNames MUST BE lowerCASE or you will get empty results.
I made some more corrections to the declaration:
Delphi-Quellcode:
type
  ADS_SEARCH_HANDLE = THandle;
  PADS_SEARCH_HANDLE = ^ADS_SEARCH_HANDLE;
  PADS_SEARCH_COLUMN = ^ads_search_column;
// *********************************************************************//
// 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;
                        var pSearchColumn: ads_search_column): HResult; stdcall;
    function FreeColumn(var pSearchColumn: ads_search_column): HResult; stdcall;
    function CloseSearchHandle(hSearchResult: ADS_SEARCH_HANDLE): HResult; stdcall;
  end;
Accessing the search results will currently not work because the declaration of ADS_SEARCH_COLUMN is totally wrong in the typelib, so while this code should be correct the results cannot be displayed because of the wrong declaration:
Delphi-Quellcode:
  while DirSearch.GetNextRow(SearchHandle) <> S_ADS_NOMORE_ROWS do
  begin
    for i := 0 to Length(ColNames) - 1 do
    begin
      hr := DirSearch.GetColumn(SearchHandle, ColNames[i], col);
      if succeeded(hr) then
      begin
        // note that the typelib doesn't know the proper typed pointer and the anonymous union in it
        OutputDebugString(col.pADsValues^.__MIDL_0010.CaseIgnoreString);
        DirSearch.FreeColumn(col);
      end;
    end;
    // Do something with result
  end;
See my blog blog
See our Jedi blog
  Mit Zitat antworten Zitat