Solved

Delphi and static libraries

Posted on 1997-08-18
5
1,034 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
[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
  • 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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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