Solved

Delphi and static libraries

Posted on 1997-08-18
5
979 Views
Last Modified: 2010-04-06
I have a 3rd party static library (.LIB) to which I need to make function calls from within a Delphi application. I need to link this static library into the Delphi application. How do I do that?
0
Comment
Question by:trinitech
  • 2
  • 2
5 Comments
 

Author Comment

by:trinitech
ID: 1341782
Edited text of question
0
 
LVL 1

Expert Comment

by:fsanchez
ID: 1341783
What compiler and version was used to create that library?
0
 

Author Comment

by:trinitech
ID: 1341784
Not quite sure about the compiler and version which was used to create the statis library, but it was not Borland C++.
Just out of curiosity, how would that matter anyway?
0
 
LVL 1

Expert Comment

by:fsanchez
ID: 1341785
 If you want to link that library it needs to be compatible with your compiler. The lasts Borland C++ compilers are compatible with Delphi (Borland C++ 5.0 and Borland C++ Builder).
  Keep in mind that even Delphi2 and Delphi3 can't use the same DCUs.
  I think that you will not be able to link that DCU anyway. You could create a DLL with a compatible compiler exporting that function calls. Then you could use that DLL from Delphi.
0
 
LVL 1

Accepted Solution

by:
arh earned 200 total points
ID: 1341786
Most probably, what you want to do is impossible. But you can try anyhow ;-).
  First, your lib 'bitness' should match one of Delphi. 16-bit
libraries may be called from only Delphi 1, and 32-bit - only  
from Delphi 2 or 3.
  Second, you should know what 'calling convention' is used by
functions in the library. Delphi 1 supports only pascal (the default) and cdecl, Delphi 2 - pascal, cdecl, stdcall, and register.
Functions written in C are usually cdecl.
  Third, you should split your library into separate object files. This can be done by tlib utility from Borland C, or by any 'librarian' utility. To get the list of object files in library:
    tlib library.lib, library.lst
To extract object files from library:
    tlib library.lib *obj1.obj *obj2.obj
  At last, suppose you have file foo.obj, which contains function foo, written in C and looking in C as
  int foo( int a, char *b )
To make it available from Delphi, you should write:
  unit foo;
  interface
  function _foo( a: integer; b: pchar ): integer; cdecl;
  implementation
  function _foo; external;
  {$L foo.obj}
  end.
Names of the functions should be given exactly as they appear in library.lst file (here _foo instead of foo).
All functions from the library should be declared in one unit.
You don't need to know which .obj file contains wich function,
just declare needed functions and procedures from the library
and include _all_ object files by $L directives.
  But even when you succesfully compile your program, it may not work. It may not work if any function accepts or returns
floating-point value. It will not work if any function in library
makes a call to standard C library function. Or it just will crash
with no apparent reason.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

895 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

19 Experts available now in Live!

Get 1:1 Help Now