-- Rich
Here is the code:
- Code: Select all
library FirstCom;
uses
ComServ,
NumIntf in 'NumIntf.pas',
ObjFact in 'ObjFact.pas' {Number: CoClass};
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.RES}
begin
end.
- Code: Select all
unit NumIntf;
interface
Type
INumber = interface
['{9421DE43-A260-42B7-81FB-33FAA1E9C6FA}']
function GetValue: Integer; stdcall;
procedure SetValue(New:Integer); stdcall;
procedure Increase; stdcall;
end;
implementation
end.
- Code: Select all
unit ObjFact;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, ActiveX, Classes, ComObj,NumIntf;
type
TNumber = class(TComObject,INumber)
Private
FValue : Integer;
protected
function GetValue: Integer; stdcall;
procedure SetValue(New:Integer); stdcall;
procedure Increase; stdcall;
public
procedure Initialize; override;
destructor Destroy; override;
end;
const
Class_Number: TGUID = '{CFA64B12-05D0-437B-AA9F-CD6D82746D46}';
implementation
uses ComServ;
destructor TNumber.Destroy;
begin
inherited;
MessageBox (0, 'Object Destroyed',
'TDLLNumber', mb_OK); // API call
end;
function TNumber.GetValue: Integer;
begin
Result := fValue;
end;
procedure TNumber.Increase;
begin
Inc (fValue);
end;
procedure TNumber.Initialize;
begin
inherited;
fValue := 10;
end;
procedure TNumber.SetValue(New: Integer);
begin
fValue := New;
end;
initialization
TComObjectFactory.Create(ComServer, TNumber, Class_Number,
'Number', 'Simple Interface', ciMultiInstance, tmApartment);
end.