[fpc-devel] Using Macros for IInterface
Graeme Geldenhuys
graeme at geldenhuys.co.uk
Wed Sep 26 12:16:56 CEST 2012
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!!
Cheers,
- Graeme -
More information about the fpc-devel
mailing list