加分:老问题:关于EXE的资源替换,只用API解决。求例子,完整,适用给分(200分)

晶晶

Unregistered / Unconfirmed
GUEST, unregistred user!
我刚刚遇到一个问题:<br>在为一个程序改资源时,用beginupdateresource,updateresource,endupdateresource<br>几个函数时问题百出。虽然API说明中说的明白,但还是很多问题出来,实在没有辙,上来<br>求救了!千万别跟我说分析PE结构,那个读取资源还可以(几层循环也不简单),导入资<br>源嘛(更难了),我还没有那个算法功力,最好有全部用API函数更换资源的例子,更<br>换的资源内容要包括:ICON,BITMAP,STRING,总之,越详细越好!!!分数先300,成功<br>后加200,一个问题500分,决不食言!
 
这个问题加上&lt;a&gt;http://www.delphibbs.com/delphibbs/dispq.asp?lid=1400281&lt;/a&gt;的300<br>分,凑起500分。<br>再说一下要求:<br>假设我有一个软件flashget.exe,他的EXE中有个标号128号的位图资源,我想用一副现成的<br>BMP图片替代他,请问有什么好的办法吗??<br>有详细的例子发分!
 
没有人知道吗?<br>不会吧,看来这里也没有混头了。<br>只有自己解决了,分什么时候发待定!
 
从MSDN翻译过来且试验成功了的代码。<br>只能从一个Exe文件的Resource加到另一个EXE里面,应该修改一下就可以达到其他目的吧<br>比如从文件装载等, 你看一下怎么改吧,我有空再帮你看一下。 [:)]<br><br>//在Form上放两个EDIT,一是edtExe1, 一是edtExe2<br>//点击Button后把edtExe1里的RCD_DATA: TAboutForm添加到edtExe2里面。<br>procedure TFormMain.btnUpdateClick(Sender: TObject);<br>var<br>&nbsp; hResLoad: HRSRC; // handle to loaded resource<br>&nbsp; hExe: THandle; // handle to existing .EXE file<br>&nbsp; hRes: HRSRC; // handle/ptr. to res. info. in hExe<br>&nbsp; hUpdateRes: THandle; // update resource handle<br>&nbsp; lpResLock: Pointer; // pointer to resource data<br>&nbsp; Result: Boolean;<br>begin<br>&nbsp; // Load the .EXE file that contains the dialog box you want to copy.<br>&nbsp; hExe := LoadLibrary(PChar(edtExe1.Text));<br>&nbsp; if hExe = 0 then<br>&nbsp; &nbsp; RaiseLastOSError;<br>&nbsp; // Locate the dialog box resource in the .EXE file.<br>&nbsp; hRes := FindResource(hExe, 'TAboutForm', RT_RCDATA);<br>&nbsp; if hRes = 0 then<br>&nbsp; &nbsp; RaiseLastOSError;<br>&nbsp; // Load the dialog box into global memory.<br>&nbsp; hResLoad := LoadResource(hExe, hRes);<br>&nbsp; if hResLoad = 0 then<br>&nbsp; &nbsp; RaiseLastOSError;<br>&nbsp; // Lock the dialog box into global memory.<br>&nbsp; lpResLock := LockResource(hResLoad);<br>&nbsp; if lpResLock = nil then<br>&nbsp; &nbsp; RaiseLastOSError;<br>&nbsp; // Open the file to which you want to add the dialog box resource.<br>&nbsp; hUpdateRes := BeginUpdateResource(PChar(edtExe2.Text), False);<br>&nbsp; if hUpdateRes = 0 then<br>&nbsp; &nbsp; RaiseLastOSError;<br>&nbsp; // Add the dialog box resource to the update list.<br>&nbsp; Result := UpdateResource(hUpdateRes, // update resource handle<br>&nbsp; &nbsp; RT_RCDATA, // change dialog box resource<br>&nbsp; &nbsp; 'TAboutForm', // dialog box name<br>&nbsp; &nbsp; MakeLong(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language<br>&nbsp; &nbsp; lpResLock, // ptr to resource info<br>&nbsp; &nbsp; SizeofResource(hExe, hRes)); // size of resource info.<br>&nbsp; if not Result then<br>&nbsp; &nbsp; RaiseLastOSError;<br>&nbsp; // Write changes to other EXE and then close it.<br>&nbsp; if not EndUpdateResource(hUpdateRes, False) then<br>&nbsp; &nbsp; RaiseLastOSError;<br><br>&nbsp; // Clean up.<br>&nbsp; if not FreeLibrary(hExe) then<br>&nbsp; &nbsp; RaiseLastOSError;<br>end;<br>
 
www.pediy.com<br>自己找找。
 
如果要真的理解类似软件的愿意,还是建议学习PE格式,有了它就没有问题啊!
 
今天上来把所有该结束的帖子结束!
 
顶部