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

2007-04-19 Thread BlueCat

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.
-- 
View this message in context: 
http://www.nabble.com/How-to-include-Carbon.h--tf3605888.html#a10074354
Sent from the Free Pascal - General mailing list archive at Nabble.com.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2007-04-19 Thread Jonas Maebe


On 19 apr 2007, at 11:01, BlueCat wrote:

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


Including that header that does not add any code to your dynamic  
library, so the actual requirement has to be something else. I know  
someone who is using an FPC-compiled dynamic library in a (universal)  
REALBasic program, so it is definitely possible.


Unfortunately, I am not familier to C, so that, I want to write the  
library

in FPC.  How it can be achieved in FPC?


The closest equivalent is the FPCMacOSAll unit. But this will not add  
any code to your program if you don't call any of its routines,  
similarly to including Carbon/Carbon.h



Could you give me some suggestions?

I have used CarbonEventsCore.ppu, but found not sufficient enough.   
The

application still crashes in certain circumstances.


The crashes are probably due to a bug in the 2.0.4 compiler, not due  
to not including Carbon/Carbon.h or so. Try installing a snapshot:
ftp://ftp.freepascal.org/pub/fpc/snapshot/v21/powerpc-macosx/ 
fpc-2.1.1.powerpc-macosx.dmg


Further, make sure that all routines which you call from the  
REALBasic program have the calling convention mwpascal. You can  
switch this calling convention on in all Pascal sources by adding  
this at the top:


{$calling mwpascal}


Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2007-04-19 Thread Ingemar Ragnemalm



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

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2007-04-19 Thread BlueCat


Ingemar Ragnemalm wrote:
 
 
 So the Pascal code compiles, links with the RB code, but crashes when it 
 runs? How far does it run?
 [snip]
 
 

Thanks you, Jonas and Ingmal.  Here is an example.

Library stub;
{$calling mwpascal}
uses CarbonEventsCore;

function aint(i : smallint) : smallint;
begin
  aint := succ(sqr(i))
end;

exports
  aint name '_aint',
  aint;

end.

I compiled this with FPC 2.1.1 (as suggested by Jonas) and got a .dylib
file.  This can be called REALbasic(Rb) through Soft Declare statement.  The
Rb application runs for some extents.  The function aint is successfuly
called. Rb app displays its result correctly.  If you select Quit from
application menu, it quits.  But if you open a modal dialog (e.g. that to
get a file for opening) from the application and make scrolls, looking
around directories etc. , the application crashes.

Of course, crash does not occure before calling function aint.

I have tryed cdecl and stdcall calling conventions, but the results are
same.

CarbonEventsCore really does something.  Without CarbonEventsCore, the
application won't open a modal dialog but crashes at launching it.

I have considered switching Rb to Lazarus.  But Lazarus currently lacks
components to handle MPEG2 or Quicktime movie files.  That's the main reason
why I use Rb instead.
-- 
View this message in context: 
http://www.nabble.com/How-to-include-Carbon.h--tf3605888.html#a10091628
Sent from the Free Pascal - General mailing list archive at Nabble.com.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal