Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delphi and static libraries

Posted on 1997-08-18
5
Medium Priority
?
1,076 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 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