修改EXE中的位图出现的问题(50)

  • 主题发起人 主题发起人 cooldren
  • 开始时间 开始时间
C

cooldren

Unregistered / Unconfirmed
GUEST, unregistred user!
function ReplaceMediaRes2(SrcFileName:String;MediaFileName:String):Boolean;var bitmap:TBitmap; MM:TMemorystream; buffer:PChar; hUpdateRes:THandle;begin result:=false; if not FileExists(SrcFileName) then begin MessageBox(Application.Handle,pchar('打开文件:'+SrcFileName+'出错'),pchar(Application.Title),MB_ICONERROR); exit; end; if not (FileExists(MediaFileName)) then begin MessageBox(Application.Handle,pchar('打开文件:'+MediaFileName+'出错'),pchar(Application.Title),MB_ICONERROR); exit; end; MM:=TMemorystream.Create; bitmap:=TBitmap.Create; bitmap.LoadFromFile(MediaFileName); bitmap.SaveToStream(MM); MM.Position:=0; try GetMem(buffer,MM.Size-0); try mm.ReadBuffer(buffer^,MM.Size-0); //开始更新资源 hUpdateRes:=BeginUpdateResource(pchar(SrcFileName),false); if(hUpdateRes=0) then begin MessageBox(Application.Handle,pchar('开始修改资源出现异常.'),pchar(Application.Title),MB_ICONERROR); exit; end; result:=UpdateResource(hUpdateRes,RT_BITMAP,MAKEINTRESOURCE(1),2052,buffer,MM.Size-0); if not result then begin MessageBox(Application.Handle,pchar('修改资源出现异常。'),pchar(Application.Title),MB_ICONERROR); exit; end; if not EndUpdateResource(hUpdateRes,false) then begin MessageBox(Application.Handle,pchar('修改资源结束出现异常.'),pchar(Application.Title),MB_ICONERROR); exit; end; finally FreeMem(buffer); end; finally mm.Free; end; result:=true; end;修改后的位图在exeScope中都不能打开,提示“当扩展内存流时内存不足”请指点谢谢
 
必须取掉位图文件头,才能更新成功.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
538
import
I
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
587
import
I
I
回复
0
查看
584
import
I
后退
顶部