Solved

cyclical dll loading

Posted on 2001-07-26
3
157 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
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now