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.

LVL 1
jturpinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
hi
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,'RasHangUpA');           if @RasHangupA = nil then showmessage('Error Loading RasHangupA');     end
    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?

0
intheCommented:
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.
0
intheCommented:
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.
0
intheCommented:
also change this line:
messagedlg( 'Error Loading DLL',mtError, [mbOk], 0);
     
to

 messagedlg(SysErrorMessage(GetLastError),mtError, [mbOk], 0);

using SysErrorMessage(GetLastError) this will give a detailed(ish) error message as to why the call to dll fails for instance if the dll name is changed to rasapi33.dll it will say that the dll cannot be found etc..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.