Solved

Static DLL

Posted on 2002-04-15
7
209 Views
Last Modified: 2010-04-04
I want to know if I can specify the path of a static DLL at runtime..something like..

Function Test; external TestPath+'TEST.DLL';

but as is TestPath must be a constant...any ideas?
0
Comment
Question by:laserpro
[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
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6943459
AFAIK you can't.  You will have to load the DLL using LoadLibrary instead.

If you haven't used LoadLibrary before, let me know and I'll post you a detailed example.

Cheers,

Stu
0
 

Author Comment

by:laserpro
ID: 6943497
so if the DLL is not in the path you have to resort to dynamic DLL loading?
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6943505
That's what my understanding of it.  Are you comfortable with dynamic loading?
0
Independent Software Vendors: 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!

 

Author Comment

by:laserpro
ID: 6943528
no..I get the jest of it but only did it one a long time ago...was hoping it would not resort to that.  A nice short, simple example would be helpful...as you know I dont need many bells and whisples for what Im doing.
0
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 50 total points
ID: 6943550
OK.  This is an short example for you.

Within the library:

function MyFunction(ID: Integer): boolean; export;
begin
  Result := ID > 5;
end;

exports
  MyFunction;

end.


Within your project:

procedure CheckID(ID: Integer);
const
  LibPath = 'C:\DLLS\TEST.DLL';

var
  MyFunc: Function(ID: Integer): boolean;
  Hnd: Integer;
begin
  Hnd := LoadLibrary(pChar(LibPath));
  if Hnd > 0 then
    try
      MyFunc := GetProcAddres(Hnd, 'MyFunc');
      try
        if MyFunc(ID) then
          ShowMessage('Yes, the ID is greater than 5')
        else
          ShowMessage('No, the ID is less than 5');
      except
        ShowMessage('Can not execute the function within the DLL');
      end;
    finally
      FreeLibrary(Hnd);
    end
  else
    ShowMessage('Library not found');
end;


This code has come COMPLETELY from memory, so if you have any problems at all, let me know and I'll actually do it in Delphi and give you any changes.  At this stage I think it should be fine.

Cheers,

Stu.
0
 

Author Comment

by:laserpro
ID: 6943564
thanks for your help.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6943576
It's a litle more work to do dynamic linking, but one of the great things about it is you can check to make sure the DLL actually exists before you use it.  Using static linking means if the DLL doesn't exist, you're application will throw up really ugly messages (and could infact terminate ungracefully).

Glad to have helped you out.  Please ask for more help if you need it.

Cheers,

Stu.
0

Featured Post

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!

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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

719 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