Solved

DLL Question

Posted on 1998-05-28
7
220 Views
Last Modified: 2012-05-04
Hi All,

Can someone give me a hand here?  I am writing a program which is, in its basic form, is a very simple front end.  What I want to do is for it to detect when a DLL has been placed into the same directory and add it too a drop down menu.

I have added all the functions declared within the DLL(s) into the main program.  I have also made the menu items invisible which call the DLL once it is found (when the DLL is detected, its menu item is turned on and vise versa).

In my FormCreate method I have done a:

TipOfTheDay.Visible := FileExists('TOTD.DLL') ;
(One example) to enable or disable that menu item when ever that DLL is detected.

However, when I compile the program, it tells me that the DLL cant be found - which is true - I havent copied it into to the correct location yet.

I copied the DLL into the correct directory, and it compiles and runs perfectly.  However, if I run the program again without the DLL, I get a message "a required DLL file,  TOTD.DLL, was not found" error.

Can some one tell me how I can let the program run without these DLLs being present, and detect when the DLLs are present???

Thanks for your help.


Stuart Johnson.
0
Comment
Question by:Stuart_Johnson
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 7

Accepted Solution

by:
ahalya earned 100 total points
ID: 1349010
you are getting this problem becasue you are using what is called a "static loading". This happens when you define your functions from your DLL  as external functions. In this case the references are resolved during compilation.

You should go for dynamic loading.  Use the "LoadLibrary" and "GetProcAddress"  functions to dynamically load the DLL functions. (you don't have to declare the "external" functions sepereately in this case). i can give you an example if you like.
0
 
LVL 7

Expert Comment

by:ahalya
ID: 1349011
Here goes a simple example that runs the function called "ProcName" from the DLL called "DLLName".



function BoolDLLFunc(DLLName, ProcName:pchar):boolean;

var  h : THandle;
     f : function:boolean;stdcall;

begin
Result := false;
h := LoadLibrary(DLLName); // Get the handle of the .DLL to be loaded...
if h <> 0 then
try
   @f := GetProcAddress(h, ProcName); // Load the procedure from the .DLL...
   if @f <> nil then
      begin;
      Result := f;      //  Execute the function
      end;
finally
   FreeLibrary(h);      // Free the library...
   end;
end;


0
 
LVL 4

Expert Comment

by:d003303
ID: 1349012
Hi Stuart,
what's the purpose of the DLL ? Do you want to create sth like an extendable front end ? If so, maybe you should define a plug-in interface for yout DLLs, that would make it much easier.

Slash/d003303
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1349013
Ahalya.
I'll give this a go and see how it works.  Looks fine.

Slash.
What do you mean by a "plug in interface".  This sounds like what I am trying to achieve.  I want the program to be expandable, say like Adobe Photo Shop is with its plug ins.

Stu.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1349014
Yo,
a plug-in interface is a set of defined function entries in a DLL. Because you are the designer of the interface, you would have to think wich functions you need. The hosting program normally parses a specified directory for files, loads them with LoadLibrary and looks if the function entries exist. If yes, the plug-in is active and bound. If no, FreeLibrary is called immediately. The basic work is done by ahalya's code.
You could easily create a plug-in object wrapper that does this stuff.

Slash/d003303
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1349015
I have got it going as per your instructions.  Works like a charm.  Thank you very much.

Stuart.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1349016
I have got it going as per your instructions.  Works like a charm.  Thank you very much.

Stuart.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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