mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 27
S
silent Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Dec 2002
Posts: 27
Hi,

i want to keep my DLL (Coded in Delphi) loaded.
I translated the C++ struct from

C++:

Code:
  void __stdcall (*LoadDll)(LOADINFO*);

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



to Delphi:

Code:
type 
  TLOADINFO = record 
    mVersion: DWORD; 
    mHwnd: HWND; 
    mKeep: BOOL; 
  end; 

procedure LoadDll(var LoadInfo: TLOADINFO); stdcall; 
begin
  // ?
end;

exports
  LoadDll;


Now when i load the DLL, mirc crashes (it didnt before).
Any ideas what wrong?

Joined: Dec 2002
Posts: 27
S
silent Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Dec 2002
Posts: 27
Hm i cant edit my last post...

i tried it like this now:

Code:
type
  PLoadinfo = ^TLoadinfo;
  TLoadinfo = record
    mVersion: DWORD;
    mHwnd: HWND;
    mKeep: BOOL;
  end;

procedure LoadDll(Loadinfo: PLoadinfo); stdcall;
begin
  ShowMessage(
    'mIRC-Version: ' +
    IntToStr(LOWORD(Loadinfo^.mVersion)) + '.' +
    IntToStr(HIWORD(Loadinfo^.mVersion))
  );
end;


if i load it with: $dll(my.dll, proc, param) now

then it shows me the dialog "mIRC-Version: 6.16" after a click on "OK" -> Crash.

Last edited by silent; 22/06/05 01:44 PM.
Joined: Jul 2005
Posts: 1
B
Mostly harmless
Offline
Mostly harmless
B
Joined: Jul 2005
Posts: 1
Tried debugging?
Checked record values?

Joined: Dec 2002
Posts: 27
G
GTS Offline
Ameglian cow
Offline
Ameglian cow
G
Joined: Dec 2002
Posts: 27
i'm doing it like that:

Code:
 
type
  TmIRCLoadInfo = packed record
    mVersion : DWORD;
    mHwnd    : HWND;
    mKeep    : Boolean;
  end;
  PmIRCLoadInfo = ^TmIRCLoadInfo;

[...]

procedure LoadDll(LoadInfo: PmIRCLoadInfo); stdcall; export;
begin
 LoadInfo.mKeep := False;
end;
 


i noticed that you're missing the export clause, that might be it, dunno ^^


proud to be baka
--> GTSdll Homepage <--
Joined: Mar 2005
Posts: 14
B
Pikka bird
Offline
Pikka bird
B
Joined: Mar 2005
Posts: 14
i have it this way:

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


Code:
 
{Export Functions}
procedure LoadDll(Loadinfo: PLoadinfo); stdcall; export;
begin
	Loadinfo.mKeep := false;
end;

function UnloadDll(mTimeOut: integer): integer; stdcall; export;
begin
	case mTimeOut of
		1: Result := 0;
	else
		begin
			Result := 1;
		end;
	end;
end;
 


Code:
exports
	LoadDll,
	UnloadDll,
...
end.
 


GreetZ BlackDex
To boldly go where no one has gone before.
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
You can also use the UnloadDll function to keep it loaded
Code:
int WINAPI UnloadDll( int timeout ) {

  // DLL unloaded because mIRC exits or /dll -u used
  if ( timeout == 0 ) {

   // clean your DLL stuff here
   return 1;
  }
  // keep DLL in memory (mIRC only wants to unload it because it's been 10 min without use)
  else 
    return 0;
}


The code is in C cause I know jackshit about Delphi =]

Joined: Mar 2005
Posts: 14
B
Pikka bird
Offline
Pikka bird
B
Joined: Mar 2005
Posts: 14
to Translate the code exactly it would be this in delphi:

Code:
function UnloadDll(mTimeOut: integer): integer; stdcall; export;
begin
  // DLL unloaded because mIRC exits or /dll -u used
  if ( mTimeOut = 0 ) then
  begin
    // clean your DLL stuff here
    result := 1;
  end

  // keep DLL in memory (mIRC only wants to unload it because it's been 10 min without use)
  else
  begin
    result := 0;
  end;
end;


Don't forget to add UnloadDll to the exports.


GreetZ BlackDex
To boldly go where no one has gone before.

Link Copied to Clipboard