在网上查了些资料,说用BeginUpdateResource、UpdateResource、EndUpdateResource这三个函数可以实现修改EXE文件的版本信息,我不会弄,请高手指教。这里还有个类似的例子:function TFormMain.ReplaceMediaRes(SrcFileName:String;MediaFileName:String):Boolean;
var
fs:TFileStream;
buffer:PChar;
hUpdateRes:THandle;
begin
result:=false;
if not FileExists(SrcFileName) then begin
MessageBox(Handle,pchar(SrcFileName+' not exists.'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
if not (FileExists(MediaFileName)) then begin
MessageBox(Handle,pchar(MediaFileName+' not exists.'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
fs:=TFileStream.Create(MediaFileName,fmOpenReadWrite);
try
GetMem(buffer,fs.size);
try
fs.ReadBuffer(buffer^,fs.size);
//begin update resource
hUpdateRes:=BeginUpdateResource(pchar(SrcFileName),false);
if(hUpdateRes=0) then begin
MessageBox(Handle,pchar('Error to begin update resource.'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
//!! the language id can get with GetUserDefaultLangID(), in english system it's 1033.
result:=UpdateResource(hUpdateRes,pchar('PLAYER'),pchar('MEDIA'),1033,buffer,fs.Size);
if not result then begin
MessageBox(Handle,pchar('Error ro update resource'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
if not EndUpdateResource(hUpdateRes,false) then begin
MessageBox(Handle,pchar('Error to end update resource.'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
finally
FreeMem(buffer);
end;
finally
fs.Free;
end;
result:=true;
end;
var
fs:TFileStream;
buffer:PChar;
hUpdateRes:THandle;
begin
result:=false;
if not FileExists(SrcFileName) then begin
MessageBox(Handle,pchar(SrcFileName+' not exists.'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
if not (FileExists(MediaFileName)) then begin
MessageBox(Handle,pchar(MediaFileName+' not exists.'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
fs:=TFileStream.Create(MediaFileName,fmOpenReadWrite);
try
GetMem(buffer,fs.size);
try
fs.ReadBuffer(buffer^,fs.size);
//begin update resource
hUpdateRes:=BeginUpdateResource(pchar(SrcFileName),false);
if(hUpdateRes=0) then begin
MessageBox(Handle,pchar('Error to begin update resource.'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
//!! the language id can get with GetUserDefaultLangID(), in english system it's 1033.
result:=UpdateResource(hUpdateRes,pchar('PLAYER'),pchar('MEDIA'),1033,buffer,fs.Size);
if not result then begin
MessageBox(Handle,pchar('Error ro update resource'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
if not EndUpdateResource(hUpdateRes,false) then begin
MessageBox(Handle,pchar('Error to end update resource.'),pchar(Application.Title),MB_ICONERROR);
exit;
end;
finally
FreeMem(buffer);
end;
finally
fs.Free;
end;
result:=true;
end;
解决方案 »
- delphi 动态验证码提示“invalid gif signature”
- 高分求助:如何生成供Delphi链接的obj文件
- 请教在FilterGraph的onGraphComplete事件问题
- 各位大哥帮帮忙,COPY字符串怎么不行?
- 超级菜鸟 如何获取TForm.formshow()
- 如何实现多用户批量提交记录到服务器上 (百分送上 高手快来)
- 我写好了应用程序,在打包时想改变图标,请教各位怎样改变?
- 怎么根据TreeView选中的节点名,查询数据库中内容
- 在主-从结构表中的主表删除数据,用什么事件来判断从表有对应的数据比较好?我用了beforedelete、ondeleteerror都没反应。
- 有谁知道《delphi 4技术内幕》有没有最新的版本?或者更好的书籍?来者有分!
- 元旦快乐,如何让应用程序空间变小啊!delphi,在线等
- 如何自动配置ODBC数据源(ACCESS)
if (NULL != hResource)
{
UINT uTemp;
TCHAR strSubBlock[256];
LPTSTR pValueBuffer;
_stprintf(strSubBlock, _T("\\StringFileInfo\\%04x%04x\\CompanyName"),
lpTranslate->wLanguage,
lpTranslate->wCodePage);
if (VerQueryValue(lpBuffer, (LPTSTR) ((LPCTSTR) strSubBlock), (LPVOID *) &pValueBuffer, &uTemp) != FALSE)
{
_tcscpy(pValueBuffer, _T("My Corp"));
if (UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO), lpTranslate->wLanguage, lpBuffer, dwSize) != FALSE)
{
if (EndUpdateResource(hResource, FALSE) == FALSE)
dwResult = GetLastError();
}
else
dwResult = GetLastError();
}
}