0

在我的项目中,我有一些文件要复制到程序文件目录中,并为一个可执行文件和其他工作(如安装)创建快捷方式。

我想在我的应用程序中使用包中的存储文件来执行此操作,例如 CAB 文件并在进度条中显示安装。

首先我想到了一个 msi 包装器,但有些用户说它太慢了!

我怎样才能以最好的方式做到这一点?

4

1 回答 1

4

这是一个开始的小模板:

unit Unit1;

interface

uses
    Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    StdCtrls
    , JwaMsi, windows // Units needed for MSI manipulation & for some type declarations

type

    { TForm1 }

    TForm1 = class(TForm)
        btnDoIt: TButton;
        lbxMsg: TListBox;
        procedure btnDoItClick(Sender: TObject);
    private
        { private declarations }
    public
        { public declarations }
    end;

var
    Form1: TForm1;

implementation

{$R *.dfm}

// Callback function
// Here you must handle type and content of messages from MSI (see MSDN for details)
function MSICallback(pvContext: LPVOID; iMessageType: Cardinal; szMessage: LPCSTR): Integer; stdcall;
var
    s: string;
begin
    // Convert PChar to string. Just for convenience.
    s := szMessage;

    // Add info about message to the ListBox
    Form1.lbxMsg.Items.Add(Format('Type: %d, Msg: %s', [iMessageType, s]));

    // Repaint form (may be it is not necessary)
    Form1.Refresh;
    Application.ProcessMessages;

    If iMessageType = INSTALLMESSAGE_TERMINATE then
        ShowMessage('Done');
end;

{ TForm1 }

procedure TForm1.btnDoItClick(Sender: TObject);
begin
    // Do not show native MSI UI
    MsiSetInternalUI(INSTALLUILEVEL_NONE + INSTALLUILEVEL_SOURCERESONLY, nil);

    // Set hook to MSI
    MsiSetExternalUI(
        @MSICallback, // Callback function
        $FFFFFFFF,    // Receive all types of messages
        nil);

    // Install product (change path to installation package)
    MsiInstallProduct(
        'D:\install\games\_old\corewar\nMarsFull.0.9.5.win.msi',
        nil);
end;

end.
于 2013-03-09T16:25:33.650 回答