Com Library

Please discuss general Delphi programming topics here.

Com Library

Postby rhartl » November 28th, 2006, 8:02 pm

I've been trying to create a com library(a DLL with a com interface). I have used the wizard for an ActiveX library to create the Com interface, generated a unit with the interface definition and GUID, and then used the COM object wizard to create the object. I put the interface definition into the class definition inheritance list and created all the necessary methods. It compiles. But Run/Register ActiveX Server it is grayed out so I can't register the thing. I am stuck, anyone know how to do this?
-- 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.
rhartl
Active Member
Active Member
 
Posts: 11
Joined: June 12th, 2006, 2:30 am

Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 19 guests

cron