DelphiFAQ Home Search:

Display the 'Choose Computer' dialog in a Delphi application

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

How can I display the 'Choose Computer' dialog in my Delphi application?

Answer:

The "Choose Computer" dialog is provided by network services (NTLANMAN.DLL) for Windows 2k/NT/XP to display the servers and their computers. The code below follows these steps:
  1. dynamically load the DLL with LoadLibrary('NTLANMAN.DLL');
  2. bind the function with GetProcAddress()
  3. call this function (result returned in buffer of characters)
  4. free the library

You can call it as shown in the button's onClick event handler.

{------------------------------------------------------------------------
  Der "Computer auswählen" Dialog ist ein Dialog von Windows
  2k/NT/XP (NTLANMAN.DLL) mit einer ListView in dem der Server
  und die dazugehörigen Computer angezeigt werden.

  The "Choose Computer" dialog is provided by network services
  (NTLANMAN.DLL) for Windows 2k/NT/XP to display the servers
  and their computers.
 ------------------------------------------------------------------------}
type
  TServerBrowseDialogA0 = function(HWND: HWND; pchBuffer: Pointer;
                                   cchBufSize: DWord) : bool;
    stdcall;

{sc-----------------------------------------------------------------------
  Name:       ShowServerDialog
  Parameters:
     AHandle
-----------------------------------------------------------------------sc}
function ShowServerDialog(AHandle: THandle) : string;
var
  ServerBrowseDialogA0: TServerBrowseDialogA0;
  LANMAN_DLL: DWord;
  buffer: array [0..1024] of Char;
  bLoadLib: boolean;
begin { ShowServerDialog }
  LANMAN_DLL := GetModuleHandle('NTLANMAN.DLL');

  if LANMAN_DLL=0 then
  begin
    LANMAN_DLL := LoadLibrary('NTLANMAN.DLL');

    bLoadLib := True
  end; { LANMAN_DLL=0 }
  if LANMAN_DLL<>0 then
  begin
    @ServerBrowseDialogA0 := GetProcAddress(LANMAN_DLL, 'ServerBrowseDialogA0');

    ServerBrowseDialogA0(AHandle, @buffer, 1024);

    if buffer[0]='\' then
    begin
      Result := buffer
    end; { buffer[0]='\' }
    if bLoadLib then
      FreeLibrary(LANMAN_DLL)
  end; { LANMAN_DLL<>0 }
end; { ShowServerDialog }


{sc-----------------------------------------------------------------------
  Name:       TForm1.Button1Click
  Parameters:
     Sender
-----------------------------------------------------------------------sc}
procedure TForm1.Button1Click(Sender: TObject);
begin { TForm1.Button1Click }
  Label1.Caption := ShowServerDialog(Form1.Handle)
end; { TForm1.Button1Click }

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: