1,184
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.Button2Click(Sender: TObject);
type
PLANGANDCODEPAGE = ^LANGANDCODEPAGE;
LANGANDCODEPAGE = record
wLanguage: Word;
wCodePage: Word;
end;
var
mSize: Integer;
mLen, mLen1: UINT;
mTranslate, mFixV: Pointer;
mHExe, mRes: THandle;
mVersion: array of Byte;
mFixVersion: VS_FIXEDFILEINFO;
mFixVersion1: PVSFixedFileInfo;
mLang: PLANGANDCODEPAGE;
fm:pchar;
nver:pchar;
begin
fm:=pchar('Project1.exe');
// fm:=pchar(ParamStr(0));
mSize := GetFileVersionInfoSize(fm, mRes);
if mSize=0 then
begin
ShowMessage('GetFileVersionInfoSize 错:'+SysErrorMessage(GetLastError));
exit;
end;
SetLength(mVersion, mSize);
GetFileVersionInfo(fm, mRes, mSize, mVersion);
VerQueryValue(mVersion, '', mFixV, mLen);
mFixVersion1 := PVSFixedFileInfo(mFixV);
mFixVersion1^.dwFileVersionMS := 12 shl 16 + 34;
mFixVersion1^.dwFileVersionLS := 56 shl 16 + 78;
mHExe := BeginUpdateResource(fm, false);
if mHExe=0 then
begin
ShowMessage('BeginUpdateResource 错:'+SysErrorMessage(GetLastError));
exit;
end;
if VerQueryValue(mVersion, 'VarFileInfo\Translation', mTranslate, mLen) then
begin
mLang := PLANGANDCODEPAGE(mTranslate);
if UpdateResource(mHExe, RT_VERSION, MakeIntResource(1), mLang^.wLanguage, mVersion, mSize) then
begin
if not EndUpdateResource(mHExe, false) then
ShowMessage('UpdateResource 错:'+SysErrorMessage(GetLastError));
end else
ShowMessage('UpdateResource 错:'+SysErrorMessage(GetLastError));
end else
ShowMessage('VerQueryValue 错:'+SysErrorMessage(GetLastError));
FreeLibrary(mHExe);
end;