Title: How to create a base class with a non-reference counted implementation of IUnknown
unit BaseNonRefcountIntfObjU;
interface
type
{: Derive classes that need a non-reference counted IUNknown
implementation from this class. }
TNonRefcountInterfacedObject = class(TObject, IUnknown)
protected
{ IUnknown }
function QueryInterface(const IID : TGUID; out Obj): HResult;
stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
end;
implementation
uses Windows;
function TNonRefcountInterfacedObject.QueryInterface(const IID : TGUID;
out Obj): HResult;
begin
if GetInterface(IID, Obj) then
Result := S_OK
else
Result := E_NOINTERFACE
end;
function TNonRefcountInterfacedObject._AddRef: integer;
begin
Result := -1 // -1 indicates no reference counting is taking
place
end;
function TNonRefcountInterfacedObject._Release: integer;
begin
Result := -1 // -1 indicates no reference counting is taking
place
end;
end { BaseNonRefcountIntfObjU }.