Board index » delphi » Calling "C LIB" from Turbo Pascal

Calling "C LIB" from Turbo Pascal

    I wonder if any one can tell me, how i can define C LIB ( DOS
environment ), and call it, from Pascal.

    Thank you

    E-mail -  camp...@blockbuster.pt

 

Re:Calling "C LIB" from Turbo Pascal


Quote
paulo campino wrote:
>     I wonder if any one can tell me, how i can define C LIB ( DOS
> environment ), and call it, from Pascal.

Short, simple, to the point:  You can't.

Quote
>     Thank you

>     E-mail -  camp...@blockbuster.pt

--
Scott Earnest            | SPAM protection in effect. Remove  |
setech@_ix.netcom.com    | "_" as needed for true addresses.  |
earnests@_homenet.lm.com |    UIN:1136443  EFnet:pale_blue    |
sinykal@_{*word*104}space.org  | URL: http://www.netcom.com/~setech |

Re:Calling "C LIB" from Turbo Pascal


Quote
paulo campino wrote in message <353B1D49.8F143...@domain.com>...
>    I wonder if any one can tell me, how i can define C LIB ( DOS
>environment ), and call it, from Pascal.

>    Thank you

>    E-mail -  camp...@blockbuster.pt

Using TLIB, you can extract object modules from a .LIB file to a .OBJ
file: TLIB libname *objname

Now, I've never wanted to call a C function in a .OBJ file from
Pascal, but Borland Pascal can link .OBJ files with {$L filename.obj}
so if it's in a .OBJ file it should to be possible - as long as it
doesn't call a load of other functions in other .OBJ files that you
don't have. You will have to declare the procedure as external.
Passing parameters to it might be a problem though. C uses the
opposite order to Pascal, and lets the caller clear up the stack
afterwards. Maybe declare the function as an external procedure with
no parameters, and put an inline assembler routine together to call
it?

FP

Re:Calling "C LIB" from Turbo Pascal


In article <6hik6f$hm...@news.indigo.ie>, Frank Peelo
<fpe...@portablesolutions.com> writes

Quote

>paulo campino wrote in message <353B1D49.8F143...@domain.com>...
>>    I wonder if any one can tell me, how i can define C LIB ( DOS
>>environment ), and call it, from Pascal.

>>    Thank you

>>    E-mail -  camp...@blockbuster.pt

>Using TLIB, you can extract object modules from a .LIB file to a .OBJ
>file: TLIB libname *objname

>Now, I've never wanted to call a C function in a .OBJ file from
>Pascal, but Borland Pascal can link .OBJ files with {$L filename.obj}
>so if it's in a .OBJ file it should to be possible - as long as it
>doesn't call a load of other functions in other .OBJ files that you
>don't have. You will have to declare the procedure as external.
>Passing parameters to it might be a problem though. C uses the
>opposite order to Pascal, and lets the caller clear up the stack
>afterwards.

As long as the .OBJ routine does *not* call any of the C RTL *and* was
compiled with the following parameters:

-p       Use pascal calling cnvention
-k-      Standard stack frame off
-r       Use the register variables
-u-      Underscore generation is off
-c       Compile to .OBJ - no .EXE file
-ms      Ensure small memory model
-zCCODE  Name code segment CODE
-zP      Do not create code group
-zA      Do not create code class
-zRCONST Name static data segment CONST
-zS      Do not create data group
-zT      Do not create data class
-zDDATA  Name data segment DATA
-zG      Do not create BSS group
-zB      Do not create BSS class

You will also need to save SI and DI before calling a pascal routine
from your C code and restore them afterwards.

--
Pedt Scragg                    <newsmas...@pedt.demon.co.uk>

Never curse the Crocodile's mother before crossing the river

Other Threads