?
Solved

DLL Question

Posted on 1998-05-28
7
Medium Priority
?
226 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 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