Solved

Delphi and static libraries

Posted on 1997-08-18
5
985 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

813 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

11 Experts available now in Live!

Get 1:1 Help Now