[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

DLL - LoadLibrary

Posted on 1999-12-30
4
Medium Priority
?
1,459 Views
Last Modified: 2012-08-14
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.

0
Comment
Question by:jturpin
  • 4
4 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2315671
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
 
LVL 17

Expert Comment

by:inthe
ID: 2315699
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
 
LVL 17

Expert Comment

by:inthe
ID: 2315702
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
 
LVL 17

Accepted Solution

by:
inthe earned 400 total points
ID: 2315787
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question