• 0

[Delphi] How can i keep a DLL loaded after a call?


Question

I tried searching everywhere on the net but i couldn't find what i was looking for.. at least not in delphi.. i found an example in C++ though ( in mirc help file ) but i need to keep going with delphi instead of C++ so if you please can help me i would appreciate it.

mirc help file example:

  void __stdcall (*LoadDll)(LOADINFO*);

  typedef struct {
    DWORD  mVersion;
    HWND   mHwnd;
    BOOL   mKeep;
  } LOADINFO;

thank you,

-thelord

5 answers to this question

Recommended Posts

  • 0

not sure, if this is what you are looking for or not. This is how I call c++ dll files

BTW: this is not working code, if you want me to post the complete working code let me know.

this code is used to get all the users off an NT domain controller

unit fUsers;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, Db, DBTables, DBClient, Provider;

  //user list info data structure
  type GROUP_USERS_INFO_0 = record
       grui0_name: LPWSTR;
  end;
  PGROUP_USERS_INFO_0 = ^GROUP_USERS_INFO_0;

  //user info data structure
  type USER_INFO_10 = record
    usri10_name         : LPWSTR;
    usri10_comment      : LPWSTR;
    usri10_usr_comment  : LPWSTR;
    usri10_full_name    : LPWSTR;
  end;
  PUSER_INFO_10 = ^USER_INFO_10;
  
  //external call to windows c++ libraries
  function NetGroupGetUsers(ServerName : LPCWSTR;
                          GroupName  : LPCWSTR;
                          Level      : DWORD;
                          bufptr     : Pointer;
                          prefmaxlen : DWORD;
                          var entriesread, totalentries: LongWord;
                          var ResumeHandle: LongWord)
                          :Integer; stdcall; external 'netapi32.dll';

  //external call to windows c++ libraries
  function NetUserGetInfo(ServerName  : LPWSTR;
                        UserName    : LPWSTR;
                        Level       : DWORD;
                        bufptr      : Pointer)
                        :Integer; stdcall; external 'netapi32.dll';

type
  TfrmUsers = class(TForm)
  
  public 
    function getNTGroupUsers(Server, GroupName: string;Container: TListBox;
                          var buff:Pointer; var recRead,recTotal:TEdit)   :TListBox;

{*******************************************************************************
* getNTGroupUsers
*
* special funtion that interfaces with an NT domain controller and retrieves
* a list of users in a specified NT group
*
* Server    : the name of the NT domain server. ie. \\JISRD2
* GroupName : the NT group you wish to get a listing of users from
* Container : a TListBox that the list of users will be inserted into
* buff      : a pointer
* recRead   : TEdit field to report the total number of user records read
* recTotal  : TEdit field to report the total number of user reocrds
*
* return TListBox : a list of all users found in domain query
*******************************************************************************}
function TfrmUsers.getNTGroupUsers(Server,GroupName:string;Container:TListBox;
                         var buff:Pointer; var recRead,recTotal:TEdit):TListBox;
var
  lpServer, lpGroupName : LPCWSTR;
  i, ret, cnt           : Integer;
  totentr, entread      : DWORD;
  p1                    : PGROUP_USERS_INFO_0;
  resH                  : LongWord;
begin
  ret  := 0;
  i    := 0;
  resH :=0;
  GetMem(lpServer,Length(Server)*2+1);
  GetMem(lpGroupName,Length(GroupName)*2+1);
  try
    stringtowidechar(Server,lpServer,Length(Server)*2+1);
    stringtowidechar(GroupName,lpGroupName,Length(GroupName)*2+1);

    repeat
      NetGroupGetUsers(lpServer,
                       lpGroupName,
                       0,
                       @buff,
                       MAX_PREFERRED_LENGTH,
                       entread,
                       totentr,
                       resH);
      //ret = NERR_Success || ERROR_MORE_DATA
      if true then
        begin
          p1:=PGROUP_USERS_INFO_0(buff);
          for cnt:=0 to entread - 1 do
            begin
              Inc(i);
              recRead.Text  := IntToStr(i);
              recTotal.Text := IntToStr(totentr);
              Container.Items.Add(UPPERCASE(p1^.grui0_name));
              Application.ProcessMessages;
              Inc(p1);
            end;
        end
       else
          CheckReturn(ret);

       until ret <> ERROR_MORE_DATA;
  finally
    FreeMem(lpserver);
  end;
  Result := Container;
end;

end.

  • 0

I would say statically, cause it is hard coded in the code.

I'm not sure if the dll is kept in memory or not. - most likely it is not unloaded cause once dll are loaded, they dont tend to be released until the program ends or windows restarts.

Sorry I'm not much help on this.

why are you worried about unloading, loading dlls etc?

  • 0

i want my dll to stay loaded after the first call so it can process a few data and store them in variables so that they can be used in the second call. as it is right now with no extra code to keep it loaded .. after the first call it's been unloaded and the variables are gone so no data are stayed stored to be used in the second call.

i hope i didn't mess u up with my bad english.

liykh001: i'm afraid that's not the code i was expecting for but thanks anyway coz it'll be helpful on my next project :)

thank you,

-thelord

  • 0

If you want a dll to stay loaded in mIRC, this is the code you want:

library stayloaded;

uses
  SysUtils, Classes, Windows;

type
  TLoadInfo = packed record
    mVersion: DWORD;
    mHwnd: HWND;
    mKeep: Boolean;
  end;
  PLoadInfo = ^TLoadInfo;

function Hello(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin
  StrCopy( data, '/echo -a Hello World' );
  Result := 2;
end;

procedure LoadDll(LoadInfo: PLoadInfo); stdcall; export;
begin
  LoadInfo.mKeep := TRUE;
end;

procedure UnloadDll(mTimeOut: integer); stdcall; export;
begin
end;

exports
  LoadDll, UnloadDll, Hello;

{$R *.res}

begin
end.

mIRC will still unload the dll if it's not used for 10 minutes.

Hope this helps - tb.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.