修改程序版本信息问题,请我的代码错在哪里,修改后的程序看不到版本信息,但是用execope看是已经修改成功了 ( 积分: 50 )

  • 主题发起人 主题发起人 bbswing
  • 开始时间 开始时间
B

bbswing

Unregistered / Unconfirmed
GUEST, unregistred user!
请我的代码错在哪里,修改后的程序看不到版本信息,但是用execope看是已经修改成功了
var ResName : PChar;
procedure ChangeCompany (FileName : string;
NewCompany : string);
const CompanyName = 'CompanyName';
var
hUpdate : THandle;
hExe : HMODULE;
Data : WideString;
ResInfo : HRSRC;
ResData : HGLOBAL;
Adr : Pointer;
Size : DWORD;
i0, i, l : integer;
function EnumFunc (hMod : HMODULE;
lpszType : LPCTSTR;
lpszName : LPTSTR;
lParam : integer) : BOOL;
stdcall;
begin
ResName := lpszName;
Result := False;
end;

begin
hExe := LoadLibrary (PChar(FileName));
if hExe = 0 then
Exit;
ResName := nil;
EnumResourceNames (hExe, RT_VERSION, @EnumFunc, 0);
ResInfo := FindResource (hExe, ResName, RT_VERSION);
if ResInfo = 0 then
Exit;
ResData := LoadResource (hExe, ResInfo);
Adr := LockResource (ResData);
Size := SizeofResource (hExe, ResInfo);
SetLength(Data, Size div 2);
CopyMemory (@Data[1], Adr, Size);
FreeResource (ResData);
FreeLibrary (hExe);
i0 := Pos(CompanyName, Data);
i := i0 + Length(CompanyName);
while Data = #0do
Inc(i);
l := 0;
while Data[i+l] <> #0do
Inc(l);
while Data[i+l] = #0do
Inc(l);
Delete (Data, i, l);
NewCompany := NewCompany + #0;
Data[i0-2] := WideChar(Length(NewCompany));
while (Length(NewCompany) mod 2) <> 0do
NewCompany := NewCompany + #0;
Insert (NewCompany, Data, i);
Data[i0-3] := WideChar( Word(Data[i0-3]) + (Length(NewCompany) - l)*2 );
i0 := Pos('StringFileInfo', Data);
Data[i0-3] := WideChar( Word(Data[i0-3]) + (Length(NewCompany) - l)*2 );
Size := Length(Data)*2;
Data[1] := WideChar(Size);

hUpdate := begin
UpdateResource (PChar(FileName), False);
UpdateResource (hUpdate, RT_VERSION, ResName, 2052, @Data[1], Size);
EndUpdateResource (hUpdate, False);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if FileExists('1.exe') then
DeleteFile('1.exe');
CopyFile(PChar(Application.exename),PChar('1.exe'),True);
ChangeCompany('1.exe','新公司名称');
end;
 
http://www.51zhan.com 最好的网址站
http://www.51zhan.com 最好的网址站
http://www.51zhan.com 最好的网址站
 
后退
顶部