Solved

Static DLL

Posted on 2002-04-15
7
202 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

863 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