calling c-function from pascal 
Author Message
 calling c-function from pascal

Hi!

  Could anybody tell me an easy way of calling a c-function (in a .obj file)
from BP7?

Thanks, Hannes.



Wed, 18 Jun 1902 08:00:00 GMT  
 calling c-function from pascal

Quote:

> Hi!

>   Could anybody tell me an easy way of calling a c-function (in a .obj file)
> from BP7?

> Thanks, Hannes.

        There is no easy way :).  You are rather limited in what can be called
from a C object file.  For example, everything must be self contained
within the C OBJ.  That means no C calls unless you have written those
as well!


Wed, 18 Jun 1902 08:00:00 GMT  
 calling c-function from pascal

Quote:

> Hi!

>   Could anybody tell me an easy way of calling a c-function (in a .obj file)
> from BP7?

> Thanks, Hannes.

Linking with "C" obj files should be covered in the documentation
that ships with the compiler. Here is some further documentation:

From Lloyds Delphi Help File (Available on the Delphi Downloads page
of our web site).

Linking with OBJ files:

Q:  I have an OBJ file that has several assembler routines compiled into
it.  I wouldn't want to have to rewrite them.  Is there a way to use
them in a Delphi app?

A:  You don't indicate if these return values or not.  In Pascal this
matters.

If they don't, include the following near the front of your code:

 Procedure TurnOn;  External;
 Procedure TurnOff; External;

If they return values, use:

  Function TurnOn: Integer; External;
  Function TurnOff: Integer; External;

Replace Integer with whatever datatype they return.

In either case follow that with:

  {$L filename.obj}

to link in the obj file.

Joe
--
Joe C. Hecht
(Borland Delphi Developer Support)
Join the Delphi Online Discussion Forum at
http://www.borland.com/techsupport/delphi/



Wed, 18 Jun 1902 08:00:00 GMT  
 calling c-function from pascal


Quote:

>Hi!

>  Could anybody tell me an easy way of calling a c-function (in a .obj file)
>from BP7?

First make the function Pascal type. (int pascal func(par) or
something like that). Then define it as external in the pascal code and
use $L directive to load the object file.

I hope you really meant a C-function that is in a .obj file and not a
library function (or a function that uses library functions)

If you do not have the source and the function is not in the pascal
format, you'll have to reverse the order of the parameters and clear
them from the stack after each call (some assembler required). Remember
that strings in C are pointers to asciiz strings.

Quote:
>Thanks, Hannes.

Osmo


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help With Pascal Iwant to call C function from Pascal

2. how do I call Pascal functions from C?

3. calling Turbo Pascal functions from Borland C++ builder

4. how do I call Pascal functions from C?

5. Calling PASCAL procedures/functions from MSVC++

6. Calling C functions from Turbo Pascal?

7. Dll function call

8. Microsoft SQLServer calls BDE-callback function

9. Calling codebase dll functions from another dll

10. Calling Functions in DLL's

11. Calling C functions

12. Calling main function

 

 
Powered by phpBB® Forum Software