[fpc-devel] Using Macros for IInterface

Sven Barth pascaldragon at googlemail.com
Wed Sep 26 12:24:06 CEST 2012

Am 26.09.2012 12:16, schrieb Graeme Geldenhuys:
> 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;

This depends on whether we want to enable $macro in the system unit... 
@core devs: does something speak agaist it?

> And all those IFDEF's must go in your own code too when you implement a
> class with IInterface support.  Yuck!!

In your own code you are free to use macros as you see it fit.

Also we should decide what we want to call these macros, so that IDEs 
and fpdoc can "workaround" them correctly.

My suggestions (if we do indeed enable it):
intfconst for constref/const
intfdecl for stdcall/cdecl {I would not use extdecl so that there are no 
potential conflicts}


More information about the fpc-devel mailing list