Solved

DLL Question

Posted on 1998-05-28
7
203 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
  • 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

20 Experts available now in Live!

Get 1:1 Help Now