[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Static DLL

Posted on 2002-04-15
7
Medium Priority
?
214 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
Technology Partners: 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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

650 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