gpt4 book ai didi

c# - 在 InnoSetup 中访问 C# COM 对象时出现异常

转载 作者:行者123 更新时间:2023-11-30 22:30:15 44 4
gpt4 key购买 nike

我正在尝试访问使用 C# 创建和注册的 COM 对象,但没有成功。

; 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;

其中 obj.GetCustomerName() 是公开的 COM 方法。UsingCOM是命名空间,CUsingCom是类名

谁能指出我在哪里犹豫不决??

最佳答案

您需要首先注册COM dll,然后您才能创建和使用它。您可能想将 dll 提取到它的目的地,然后调用 RegisterServer在调用 CreateAboutButtonAndURLLabel 之前。

当使用 [Files] 部分时,您需要添加 regserver 属性来注册 COM 服务器,但这将在您的设置过程中复制和注册 dll 为时已晚.

关于c# - 在 InnoSetup 中访问 C# COM 对象时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9741304/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com