2

I'm trying to access a COM object created and registered using C# but without any success.

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
AppName=CoolCOM
AppVerName=CoolCOM 1.0
CreateAppDir=no
DisableProgramGroupPage=yes
DefaultGroupName=CoolCOM
UninstallDisplayIcon={app}\CoolCOM.exe
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source : "UsingCOM.dll";DestDir: "{app}"

[Code]

const
  CLSID_ShellLink = '{51E1EF73-0A8F-440a-B68F-614A83B515DB}';


procedure AboutButtonOnClick(Sender: TObject);
var Form : TSetupForm;
    OKButton,CancelButton : TNewButton;
    FormCaption : TLabel;
    Obj: Variant;
begin

{ Create the main ShellLink COM Automation object }
  Obj := CreateOleObject('UsingCOM.CUsingCom');

try
  Form := CreateCustomForm();
  Form.Clientwidth := 400;
  Form.ClientHeight := 300;
  Form.Caption :=  'VATSAG Inc.';
  Form.Color := clGray;
  Form.CenterInsideControl(WizardForm, False);

  OKButton := TNewButton.Create(Form);
  OKButton.Caption := '&OK';
  OKButton.Parent := Form;
  OKButton.Top := Form.ClientHeight - ScaleY(25);
  OKButton.Left := Form.ClientWidth - ScaleX(200);
  OKButton.ModalResult := mrOk;

  CancelButton := TNewButton.Create(Form);
  CancelButton.Caption := '&Cancel';
  CancelButton.Parent := Form;
  CancelButton.ModalResult := mrCancel;
  CancelButton.Top := OKButton.Top;
  CancelButton.Left := Form.ClientWidth - ScaleX(100);

  FormCaption := TLabel.Create(Form);
  FormCaption.Caption := Obj.GetCustomerName();  
  FormCaption.Left := ScaleY(20);
  FormCaption.Top := ScaleY(10);
  FormCaption.Width := 200;
  FormCaption.Height := 20;
  FormCaption.Parent := Form;
  FormCaption.WordWrap := True;
  FormCaption.Font.Size := 12;
  FormCaption.Font.Color := clWhite;
  FormCaption.Font.Style := [fsBold];

  Form.ActiveControl := OKButton;

  if Form.ShowModal = mrOk then begin
    MsgBox('So you agree with me :)', mbInformation, mrOk);
    end
  else begin
    MsgBox('Do you have a problem with me 8)', mbInformation, mrOk);
  end;

finally
  Form.Free();
end;

end; // EO AboutButtonOnClick

procedure CreateAboutButtonAndURLLabel(ParentForm: TSetupForm; CancelButton: TNewButton);
var
  AboutButton: TNewButton;
  URLLabel: TNewStaticText;
begin
  AboutButton := TNewButton.Create(ParentForm);
  AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  AboutButton.Top := CancelButton.Top;
  AboutButton.Width := CancelButton.Width;
  AboutButton.Height := CancelButton.Height;
  AboutButton.Caption := '&About...';
  AboutButton.OnClick := @AboutButtonOnClick;
  AboutButton.Parent := ParentForm;

end;

procedure InitializeWizard();
var
  Left, LeftInc, Top, TopInc: Integer;
begin
  Left := WizardForm.WelcomeLabel2.Left;
  LeftInc := (WizardForm.CancelButton.Width*3)/2 + ScaleX(8);
  TopInc := WizardForm.CancelButton.Height + ScaleY(8);
  Top := WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height - 4*TopInc;

   CreateAboutButtonAndURLLabel(WizardForm, WizardForm.CancelButton);

end;

where the obj.GetCustomerName() is the exposed COM method. UsingCOM is the namespace and CUsingCom is the name of the class

Can anyone point out where am i faltering ??

this-Me
  • 2,139
  • 6
  • 43
  • 70
  • Where do you have the exeption? while creating the COM object or calling Obj.GetCustomerName? is the COM already registered (you need to first register the UsingCOM.dll before you can use it)? – kobik Mar 16 '12 at 17:16
  • Can you reference the TLB instead of the DLL? – code4life Mar 16 '12 at 19:24

1 Answers1

3

You need to first register the COM dll before you can create and use it. You might want to extract the dll to it's destination and then call RegisterServer before you call CreateAboutButtonAndURLLabel.

When using the [Files] section you need to add regserver attribute to register the COM server, but this will copy and register the dll too late in your setup process.

kobik
  • 21,001
  • 4
  • 61
  • 121
  • As i have mentioned i have registered the Dll... But i will try adding the regserver attr option – this-Me Mar 16 '12 at 18:33
  • Sorry, I misread your question. I still can't understand your setup process. what wlil happen on a machine that dose not have the dll registered yet (with regsvr32)? the file copy process in being done after the wizard window is created... anyway, try to load the COM dll from other application than inno to verify that it's correctly registered. – kobik Mar 16 '12 at 22:18