Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cyclical dll loading

Posted on 2001-07-26
3
Medium Priority
?
170 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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

670 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