[fpc-pascal] How to include Carbon.h?

Ingemar Ragnemalm ingemar at ragnemalm.se
Thu Apr 19 12:32:51 CEST 2007


> Hello, Pascal folks,
>
> I'm using FPC 2.0.4 on MacOSX 1.4.9 PPC and trying to write a Pascal library
> that is externally called from REALbasic (Rb).  But Rb needs Carbon.h header
> included in dylibs which are called by Rb programs.
>
> In C, it's easy:
>
> #include "Carbon/Carbon.h"
>
> Unfortunately, I am not familier to C, so that, I want to write the library
> in FPC.  How it can be achieved in FPC? 
> Could you give me some suggestions?
>
> I have used CarbonEventsCore.ppu, but found not sufficient enough.  The
> application still crashes in certain circumstances.
>   

So the Pascal code compiles, links with the RB code, but crashes when it 
runs? How far does it run?

It can't possibly be a problem with calling conventions? Pascal routines 
that you need to call from C need to be declared appropriately, with 
"cdecl" or "MWPascal" (which are equivalent, I think). Could that be the 
problem? Then Jonas' suggestion to use "{$calling mwpascal}" could be 
just what you need. Then your calls will be compiled to use C calling 
conventions.

Another problem when mixing languages is the Pascal RTL. You might need 
to link with that. (That is not necessarily trivial, I am having trouble 
with that myself.) But that doesn't sound like your problem, right?


/Ingemar




More information about the fpc-pascal mailing list