求 updateresource的实例(0分)

  • 主题发起人 主题发起人 freddyzhu
  • 开始时间 开始时间
F

freddyzhu

Unregistered / Unconfirmed
GUEST, unregistred user!
请教如何向资源文件内添加、修改 资源<br>api 函数内有3函数,但我不知如何传参数<br>不知各位可有用过,请出示实例<br>beginUpdateResource<br>UpdateResource<br>EndUpdateResource<br>
 
[:)]我这里有一个,但不太完整,本人也正在琢磨更新资源的问题,不知有没有兴趣合作一下?
 
delphi_exe:<br>updateresource只能休改xxx.exe文件内的资源<br>且该xxx.exe文件不能正在使用,<br>我能成功添加修改 &nbsp;rt_sting &nbsp;rt_rcdata 但添加 rt_bitmap时只有名称却没有对应的数据<br>不知为何?<br>我原本想休改xxx.res内的资源。所有updateresource和我的设想有点差距,不知你可有别的<br>好方法通过程序来编辑xxx.res文件。<br>
 
freddyzhu:[:)]<br>我在用updateresource添加修改exe文件的 &nbsp;rt_sting &nbsp;时有些问题,你说你已经成功添加修改 &nbsp;rt_sting &nbsp;rt_rcdata ,<br>能将你的那一部分源码贴出来吗?<br><br>以下是你要的实例,仅供参考。<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>Function MAKELANGID(p,s:Word) : Word;<br>begin<br>&nbsp; &nbsp;Result:=( ( s shl 10 ) or p );<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var <br>lpResLock :Pointer; &nbsp; &nbsp;// pointer to resource data<br>hExe,hRes,hResLoad,hUpdateRes:THandle; &nbsp; &nbsp; &nbsp; &nbsp;// handle to existing .EXE file<br>Getresult:Boolean;<br>begin<br>// Load the .EXE file that contains the dialog box you want to copy. <br>hExe := LoadLibraryex(Pchar('hand.exe'),0,LOAD_LIBRARY_AS_DATAFILE);<br>&nbsp;<br>if (hExe =0 ) then Showmessage('Could not load exe.');<br><br>&nbsp;<br>// Locate the dialog box resource in the .EXE file. <br><br>hRes := FindResource(hExe, '#6', RT_DIALOG);<br>&nbsp;<br>if (hRes = 0 ) then Showmessage('Could not locate dialog box.');<br><br>// Load the dialog box into global memory. <br>hResLoad := LoadResource(hExe, hRes);<br><br>if (hResLoad =0 ) then Showmessage('Could not load dialog box.');<br><br>&nbsp;<br>// Lock the dialog box into global memory. <br>lpResLock := LockResource(hRes);<br>&nbsp;<br>if (lpResLock = Nil ) then Showmessage('Could not lock dialog box.');<br>{<br>Dynamic updating of the resources in portable executable (PE) files is not<br>supported on Windows 95 nor on Windows 95 OSR 2. The following functions<br>are not supported:<br>1:BeginUpdateResource<br>2:EndUpdateResource<br>3:UpdateResource<br>}<br><br>// Open the file to which you want to add the dialog box resource.<br><br>hUpdateRes := BeginUpdateResource('foot.exe', False);<br><br>if (hUpdateRes =0 ) then Showmessage('Could not open file for writing.');<br><br>// Add the dialog box resource to the update list.<br>Getresult := UpdateResource(hUpdateRes, &nbsp; &nbsp; &nbsp; // update resource handle<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RT_DIALOG, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // change dialog box resource<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'#6', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// dialog box name<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MAKELANGID(LANG_NEUTRAL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SUBLANG_NEUTRAL), &nbsp; &nbsp; &nbsp; &nbsp;// neutral language ID<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpResLock, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ptr to resource info<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SizeofResource(hExe, hRes)); // size of resource info.<br><br>if (Getresult = False) then Showmessage('Could not add resource.');<br><br>// Write changes to FOOT.EXE and then close it.<br>if ( Not EndUpdateResource(hUpdateRes, False)) then Showmessage('Could not write changes to file.');<br><br>// Clean up. <br>if ( Not FreeLibrary(hExe)) then Showmessage('Could not free executable.');<br><br>end;<br><br><br>end.
 
&nbsp; 如此,如此,大家可以好好交流一下了,<br>本人也正在研究替换EXE文件的图标德问题。 &nbsp;鼓励一下!
 
后退
顶部