jturpin
asked on
DLL - LoadLibrary
I am attempting to load a DLL by calling:
RasHandle:= LoadLibrary('rasapi32.dll' );
However I am getting the error:
"Initialization of the dynamic link library <<my fn and path>> failed. The process is
terminating abnormally."
Would someone please give me some hints as what I should look for.
Sincerely,
John.
RasHandle:= LoadLibrary('rasapi32.dll'
However I am getting the error:
"Initialization of the dynamic link library <<my fn and path>> failed. The process is
terminating abnormally."
Would someone please give me some hints as what I should look for.
Sincerely,
John.
sorry that was bad example with many errros here is tested one:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Ras;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TRasHangupFunc = function(RasConn: ThRASCONN): DWORD; stdcall;
var
Form1: TForm1;
RasHangupA: TRasHangupFunc;
DLLHandle : THandle;
implementation
{$R *.DFM}
procedure LoadDLLFunction;
var
i : integer;
begin
DLLHandle := LoadLibrary('rasapi32.dll' );
if DLLHandle <> 0 then
begin
showmessage('dll loaded');
@RasHangupA := GetProcAddress(DLLHandle,' RasHangUpA ');
if @RasHangupA = nil then showmessage('Error Loading RasHangupA function')
else showmessage('found RasHangupA function in dll');
end
else
begin
messagedlg( 'Error Loading DLL',mtError, [mbOk], 0);
end;
end;
procedure FreeDLLFunction;
begin
if DLLHandle <> 0 then
FreeLibrary(DLLHandle);
end;
Procedure TForm1.Button1Click(Sender : TObject);
begin
LoadDLLFunction;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeDLLFunction;
end;
initialization
begin
DLLHandle := 0;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Ras;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TRasHangupFunc = function(RasConn: ThRASCONN): DWORD; stdcall;
var
Form1: TForm1;
RasHangupA: TRasHangupFunc;
DLLHandle : THandle;
implementation
{$R *.DFM}
procedure LoadDLLFunction;
var
i : integer;
begin
DLLHandle := LoadLibrary('rasapi32.dll'
if DLLHandle <> 0 then
begin
showmessage('dll loaded');
@RasHangupA := GetProcAddress(DLLHandle,'
if @RasHangupA = nil then showmessage('Error Loading RasHangupA function')
else showmessage('found RasHangupA function in dll');
end
else
begin
messagedlg( 'Error Loading DLL',mtError, [mbOk], 0);
end;
end;
procedure FreeDLLFunction;
begin
if DLLHandle <> 0 then
FreeLibrary(DLLHandle);
end;
Procedure TForm1.Button1Click(Sender
begin
LoadDLLFunction;
end;
procedure TForm1.FormDestroy(Sender:
begin
FreeDLLFunction;
end;
initialization
begin
DLLHandle := 0;
end;
end.
ps
if you dont have a ras header file to add to uses section you can get one at any of the delphi component sites.
if you dont have a ras header file to add to uses section you can get one at any of the delphi component sites.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it should work try this for instance :
type
TRasHangupFunc = function(RasConn: THRASCONN): DWORD; stdcall;
var
RasHangupA: TRasHangupFunc;
DLLHandle : THandle;
....
initialization
begin
DLLHandle := nil;
end;
procdeure LoadDLLFunction;
begin
DLLHandle := LoadLibrary('rasapi32.dll'
if DLLHandle <> nil then
begin
@RasHangupA := GetProcAddress(DLLHandle,'
else
begin
messagedlg( 'Error Loading DLL',mtError, [mbOk], 0);
end;
*** Remember to free the DLL when you don't need it any more.
procedure FreeDLLFunction;
begin
if DLLHandle <> nil then
FreeLibrary(DLLHandle);
end;
does that work or give the error?