Solved

Static DLL

Posted on 2002-04-15
7
201 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
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
Comment Utility
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
Comment Utility
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
Comment Utility
That's what my understanding of it.  Are you comfortable with dynamic loading?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:laserpro
Comment Utility
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
Comment Utility
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
Comment Utility
thanks for your help.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

10 Experts available now in Live!

Get 1:1 Help Now