2012-03-16 2 views
2

C#을 사용하여 만들고 등록한 COM 개체에 액세스하려고하는데 성공하지 못했습니다.InnoSetup에서 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은 클래스 이름입니다.

아무도 내가 어리 석을 곳을 지적 할 수 있습니까 ??

+0

어디에서 예외가 있습니까? COM 개체를 만들거나 Obj.GetCustomerName을 호출 할 때? COM은 이미 등록되어 있습니다 (사용하기 전에 먼저 UsingCOM.dll을 등록해야합니다)? – kobik

+0

DLL 대신 TLB를 참조 할 수 있습니까? – code4life

답변

3

먼저 앞에 COM dll 을 등록하고 만들어야 사용할 수 있습니다. CreateAboutButtonAndURLLabel에 전화하기 전에 대상에 DLL을 추출한 다음 RegisterServer으로 전화 할 수 있습니다.

[Files] 섹션을 사용하는 경우 regserver 속성을 추가해야 COM 서버를 등록 할 수 있지만 너무 늦게 설치 프로세스에서 dll을 복사하고 등록합니다.

+0

나는 Dll을 등록했다는 것을 언급 했으므로 ...하지만 regserver attr 옵션을 추가하려고 시도합니다. –

+0

죄송합니다. 질문을 잘못 읽었습니다. 여전히 설치 과정을 이해할 수 없습니다. dlll을 아직 등록하지 않은 컴퓨터에서 (regsvr32를 사용하여) 어떤 일이 발생합니까? 마법사 창을 만든 후에 수행되는 파일 복사 프로세스 ... 어쨌든 INO가 아닌 다른 응용 프로그램에서 COM DLL을로드하려고 시도하면 올바르게 등록되었는지 확인할 수 있습니다. – kobik

관련 문제