[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Interfacing Delphi to a C Library

Is it possible to directly invoke the functions of a C library from a Delphi program? Assuming I have the .o and .h file from the C library, how do I invoke the functions of that library from the Delphi application?
0
mtrudgia
Asked:
mtrudgia
1 Solution
 
florisbCommented:
No, you can't directly (please correct me if I'm wrong... ...but I think this is the answer...).

Two possibility's:
- Rewrite the C library's to delphi units you can include.
- Restructure the code from the C library in a COM object, using COM you can make code from any language re-usable in other languages.

Floris.

 
0
 
rwilson032697Commented:
Yes you can, though there are some caveats: You need to compile the .o file with a Borland C compiler for a start...

Here's an example:

unit externalLib;

interface
  Function Fred(I : Integer):Integer;

implementation

{$L ExtLib.o}

Function Fred(i : Integer) : Integer; external;

end;

You can the call the function Fred.

Cheers,

Raymond.
0
 
mtrudgiaAuthor Commented:
Umm...

I thought of perhaps encapsulating the C library in a DLL wrapper, and using the DLL from Delphi... would this work?
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
rwilson032697Commented:
Yes, that would also work (and is the best idea if you only, say, the MS C compiler...)

You might like to note the JPEG support in delphi is jsut the C JPEG library compiled to .o files and linked in as I showed above.

Cheers,

Raymond.
0
 
mtrudgiaAuthor Commented:
Thanks,

The only thing is I've never written a DLL before.

I have an old C++ compiler (Optima++ from PowerSoft) which says it can be used to produce Windows 32-bit DLLs.

Do you know of a good web resource that might instruct me on how to write a DLL in C or C++.

Thanks again
Michael
0
 
craig_capelCommented:
Why not use Delphi to make the dll´s  i made my first one last saturday, total mess but i got there...
0
 
topkapiCommented:
you may want to study some text on calling conventions.

i recently build a delphi wrapper component around a C++ builder (tcp/ip) .dll, wich after a few design modifications (the calling conventions and event handlers) works quite well.

topkapi
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now