Первый COM-сервер
unit DllClass;
interface
uses
ActiveX, ComObj;
const
CLSID_TDllNumber: TGUID =
'{84960F62-1D49-11D1-854E-444553540000}';
type
INumber = interface
['{ECD5DAE3-1D37-11D1-854E-444553540000}']
function GetValue: Integer; stdcall;
procedure SetValue(New: Integer); stdcall;
procedure Increase; stdcall;
function RefCount: Integer; stdcall;
end;
type
TDllNumber = class(TComObject, INumber)
private
Value: Integer;
public
function GetValue: Integer; virtual; stdcall;
procedure SetValue(New: Integer); virtual; stdcall;
procedure Increase; virtual; stdcall;
function RefCount: Integer; stdcall;
procedure Initialize; override;
destructor Destroy; override;
end;
implementation
uses
Windows, ComServ, SysUtils;
procedure TDllNumber.Initialize;
begin
inherited;
Value := 10;
end;
destructor TDllNumber.Destroy;
begin
inherited;
MessageBox(0,
PChar('Object ' + IntToStr(Value) + ' Destroyed'),
'TDLLNumber', mb_OK); // API call
end;
function TDllNumber.GetValue: Integer;
begin
Result := Value;
end;
procedure TDllNumber.SetValue(New: Integer);
begin
Value := New;
end;
procedure TDllNumber.Increase;
begin
Inc(Value);
end;
function TDllNumber.RefCount: Integer;
begin
Result := inherited RefCount;
end;
initialization
TComObjectFactory.Create(
ComServer, TDllNumber, CLSID_TDllNumber,
'Md3.FirstCom', 'Md3 First COM Server',
ciMultiInstance);
end.
Скачать весь проект
|