Inno Setup スクリプト内から新しい GUID を生成する方法はありますか?
4 に答える
innosetupニュースグループアーカイブでこれを見つけました:
http://news.jrsoftware.org/news/innosetup/msg76234.html
私はそれをテストしていません。
[Code]
type
TGUID = record
D1: LongWord;
D2: Word;
D3: Word;
D4: array[0..7] of Byte;
end;
function CoCreateGuid(var Guid:TGuid):integer;
external 'CoCreateGuid@ole32.dll stdcall';
function inttohex(l:longword; digits:integer):string;
var hexchars:string;
begin
hexchars:='0123456789ABCDEF';
setlength(result,digits);
while (digits>0) do begin
result[digits]:=hexchars[l mod 16+1];
l:=l div 16;
digits:=digits-1;
end;
end;
function GetGuid(dummy:string):string;
var Guid:TGuid;
begin
if CoCreateGuid(Guid)=0 then begin
result:='{'+IntToHex(Guid.D1,8)+'-'+
IntToHex(Guid.D2,4)+'-'+
IntToHex(Guid.D3,4)+'-'+
IntToHex(Guid.D4[0],2)+IntToHex(Guid.D4[1],2)+'-'+
IntToHex(Guid.D4[2],2)+IntToHex(Guid.D4[3],2)+
IntToHex(Guid.D4[4],2)+IntToHex(Guid.D4[5],2)+
IntToHex(Guid.D4[6],2)+IntToHex(Guid.D4[7],2)+
'}';
end else
result:='{00000000-0000-0000-0000-000000000000}';
end;
function InitializeSetup(): Boolean;
begin
MsgBox(GetGuid(''), mbInformation, MB_OK);
Result := False;
end;
私はしばらくこのソリューションを使用していました (5.5.0 (a) および 5.5.1(a) を実行)。
しかし、5.5.2 (u) に更新すると、タイプの重複エラー「TGUID」が原因で、ビルド スクリプトが失敗しました。
それを修正するために、次のものを削除する必要がありました。
type
TGUID = record
D1: LongWord;
D2: Word;
D3: Word;
D4: array[0..7] of Byte;
end;
これは Unicode バージョンでのみ発生します。つまり、5.5.2 (u) には GUID タイプが組み込まれています。
これは、不必要な 16 進書式設定関数を除いた、ややクリーンな の実装ですFormatGuid
(何のためにあるのでしょうFormat
か?!)。
function FormatGuid(Guid:TGuid):string;
begin
result:=Format('%.8x-%.4x-%.4x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x', [Guid.D1, Guid.D2, Guid.D3, Guid.D4[0], Guid.D4[1], Guid.D4[2], Guid.D4[3], Guid.D4[4], Guid.D4[5], Guid.D4[6], Guid.D4[7]]);
end;
他の回答のように定義TGuid
してインポートする必要があります。CoCreateGuid
type
TGuid = record
D1: LongWord;
D2: Word;
D3: Word;
D4: array[0..7] of Byte;
end;
function CoCreateGuid(var Guid:TGuid):integer;
external 'CoCreateGuid@ole32.dll stdcall';
これを行うには、スクリプトの [Code] セクション内で宣言する Windows API 関数 CoCreateGuid ("OLE32.dll" 内) を呼び出します。申し訳ありませんが、私は Inno Setup をしばらく使用していないので、これを行う方法が正確にはわかりません。参考までに、GetWindow() 関数のサンプル API 宣言を次に示します。
Function GetWindow (HWND: Longint; uCmd: cardinal): Longint;
external 'GetWindow@user32.dll stdcall';
CoCreateGuid を使用するための VB サンプルへのリンクは次のとおりです。
http://support.microsoft.com/kb/176790
このすべてのどこかにあなたの答えがあります。