uiocprtl.pas

来自「楠楠写的DBiocp例子都是源码」· PAS 代码 · 共 63 行

PAS
63
字号
unit uIOCPRTL;

interface

uses
   SysUtils, Windows, Contnrs, Classes;

type

  //实现接口的对象
  TInterObject = class (TObject, IUnknown)
  protected
    FRefCount: Integer;
  public
    function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;

    constructor Create;
    destructor Destroy; override;
  end;

 
implementation



//实现接口的对象
constructor TInterObject.Create;
begin
  inherited Create;
  FRefCount := 1;
end;

destructor TInterObject.Destroy;
begin
  inherited Destroy;
end;

function TInterObject.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
  if GetInterface(IID, Obj) then
    Result := S_OK
  else
    Result := E_NOINTERFACE;
end;

function TInterObject._AddRef: Integer;
begin
  Result := InterlockedIncrement(FRefCount);
end;

function TInterObject._Release: Integer;
begin
  Result := InterlockedDecrement(FRefCount);
  if Result = 0 then
    Destroy; 
end;

//哈索表

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?