*i used this code : but ther is an errore on ADS_SEARCH_HANDLE can any body help me?*
Code :
unit Unapp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFormApp = class(TForm)
Button1: TButton;
private
function GetADDisplayName(const Username: String): String;
{ Private declarations }
public
{ Public declarations }
end;
var
FormApp: TFormApp;
implementation
uses
ActiveX,
JwaAdsTlb, JwaActiveDS; // From Jedi ApiLib
{$R *.dfm}
function TFormApp.GetADDisplayName(const Username: String): String;
var
hr: HRESULT;
DirSearch: IDirectorySearch;
SearchInfo: ADS_SEARCHPREF_INFO;
hSearch: ADS_SEARCH_HANDLE; // ************this has error**************
col: ADS_SEARCH_COLUMN;
Filter: String;
Attributes: array of PChar;
begin
Result := 'Undefined Result';
// Initialize COM
CoInitialize(nil);
try
// Change line below with your domain name
hr := ADsGetObject('LDAP://dc=Tbco,dc=com',
IID_IDirectorySearch, Pointer(DirSearch));
Win32Check(Succeeded(hr));
SearchInfo.dwSearchPref := ADS_SEARCHPREF_SEARCH_SCOPE;
SearchInfo.vValue.dwType := ADSTYPE_INTEGER;
SearchInfo.vValue.dwType := ADS_SCOPE_SUBTREE;
hr := DirSearch.SetSearchPreference(SearchInfo,1);
Win32Check(Succeeded(hr));
Filter := Format('(&(objectClass=user)(sAMAccountName=%s))',
[Username]);
SetLength(Attributes, 1);
Attributes[0] := 'displayName';
// When using Dynamic Array with WinApi ALWAYS use pointer to first element!
hr := DirSearch.ExecuteSearch(PWideChar(Filter),PWideChar(Attributes[0]),Length(Attributes), Pointer(hSearch));
Win32Check(Succeeded(hr));
try
hr := DirSearch.GetFirstRow(Pointer(hSearch));
Win32Check(Succeeded(hr));
hr := DirSearch.GetColumn(hSearch, Attributes[0], col);
if Succeeded(hr) then
begin
Result := col.pADsValues^.CaseIgnoreString;
DirSearch.FreeColumn(@col);
end;
finally
DirSearch.CloseSearchHandle(hSearch);
end;
finally
// UnInitialize COM
CoUninitialize;
end;
end;
end.
Delphi Error; [Error] Unapp.pas(33): Undeclared identifier: 'ADS_SEARCH_HANDLE' [Error] Unapp.pas(70): Types of actual and formal var parameters must be identical [Error] Unapp.pas(70): Incompatible types: 'Char' and 'WideChar' [Error] Unapp.pas(73): Undeclared identifier: 'CaseIgnoreString' [Error] Unapp.pas(74): Types of actual and formal var parameters must be identical [Error] Unapp.pas(77): Types of actual and formal var parameters must be identical [Fatal Error] ProjApp.dpr(5): Could not compile used unit 'Unapp.pas'
DirSearch
– David Heffernan