Solved

cyclical dll loading

Posted on 2001-07-26
3
162 Views
Last Modified: 2010-04-06
Hi
I have some DLLs like:
------------------------------------------------
library Report;
uses
  SysUtils,
  Classes,
  Main in 'Main.pas';
exports
  GetReportName name 'GetReportName';
end.

unit Main;
interface

uses Forms, Classes;
function GetReportName: String; export; stdcall;

implementation

const
  ReportName = 'Name1';

function GetReportName;
begin
  Result := ReportName;
end;

end.
------------------------------------------------


And EXE app. It looks through the given directory, finds all DLLs that have the structure described above (with the different constant "ReportName") and for instance prints the Name of the report in the DLL:

------------------------------------------------
type
  TGetReportName = function: String; stdcall;
var
  DllInstance: THandle;
  GetReportName: TGetReportName;
  ReportName: String;

. . . . .  

if ExtractFileExt(SearchRec.Name) = '.dll' then
begin
 DllInstance := LoadLibrary(PChar(SearchRec.Name));
 if DllInstance <> 0 then
 begin
  @GetReportName := GetProcAddress(DllInstance, 'GetReportName');
  if @GetReportName <> nil then
  begin
   ReportName := GetReportName;

   ShowMessage(ReportName);
  end;
  FreeLibrary(DllInstance);
 end;
end;

After finding the first DLL it's OK, but in the second iteration an exception is generated in the string:

ReportName := GetReportName;

ReportName variable unaccessible :(

What's wrong in my code?
0
Comment
Question by:vterekh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 6322436
You have to add this line to your dll:

exports GetReportName;

You can delete the "export" calling convention. It has no effect in 32bit programming anymore.

Please add ShareMem at the first location of both your exe's and your dll's uses clause.

Regards, Madshi.
0
 
LVL 1

Author Comment

by:vterekh
ID: 6325700
2 Madshi:

Thanks a lot!
Adding ShareMem it started working.

But as for the string

exports GetReportName;

it was located in the

library Report;

Probably you didn't notice it.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6325805
Yep, missed that GetReportName...  :-)

About ShareMem: When using ShareMem you have to distribute Borland's memory manager dll with your application. It's named borlndmm.dll, if I remember right. You're allowed to do so...

Regards, Madshi.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

763 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