[fpc-devel] Using Macros for IInterface

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Wed Sep 26 12:23:25 CEST 2012

On Wed, 26 Sep 2012, Graeme Geldenhuys wrote:

> On 2012-09-25 22:16, Henry Vermaak wrote:> I've used a macro for this in the 
> past.  E.g. :
>> {$macro on}
>> {$ifdef windows}
>>    {$define CCONV:=stdcall}
>> {$else}
>>    {$define CCONV:=cdecl}
>> {$endif}
>> Then use CCONV where you would specify the calling convention.
> Couldn't something like this be applied to IInterface too?  So we can get rid 
> of those horrible IFDEF lines. If you don't know what I am talking about, 
> have a look at the IInterface definition.
>       IUnknown = interface
>         ['{00000000-0000-0000-C000-000000000046}']
>         function QueryInterface({$IFDEF 
> FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : 
> longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
>         function _AddRef : longint;{$IFNDEF 
> WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
>         function _Release : longint;{$IFNDEF 
> WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
>       end;
>       IInterface = IUnknown;
> And all those IFDEF's must go in your own code too when you implement a class 
> with IInterface support.  Yuck!!

Since years I am a proponent of a libcall calling convention which translates to the
common library calling convention for the platform. i.e. stdcall on windows,
cdecl on all other platforms. A much cleaner solution IMHO.

The FPC_HAS_CONSTREF should disappear as soon as the RTL must not be
compilable with a previous version that does not have CONSTREF.
(which in fact could be 2.6.0, but someone would have to confirm that)


More information about the fpc-devel mailing list