B
benhacker
Unregistered / Unconfirmed
GUEST, unregistred user!
var WriteIcoEXE,MeIcoRes:THANDLE;beginMeIcoRes := FindResource(HInstance,'EXE','exefile');//查找自身资源文件中叫EXE的资源.WriteIcoEXE := LoadResource(HInstance, MeIcoRes);//载入这个exe的资源WRes:=FindResource(WriteIcoEXE,PChar(1), RT_ICON); //从WriteIcoEXE中查找PE图标资源..................end;最后得到的WRes是0,也就是说找不到图标资源,按理论上说上述代码没问题.我是把另一个.EXE文件放到我编写的EXE程序中,也就是说,我的程序中包含另一个EXE.现在我要读取这个EXE的图标.就这么简单的事,却让我郁闷好几天.如果我不把那个EXE做成资源文件载入我的程序,直接从外部用LoadLibrary('test.exe')再去取它的图标,一点问题没有.如下述代码.我很不解为什么,请各位老师教教我.var WriteIcoEXE,MeIcoRes:THANDLE;beginWriteIcoEXE := LoadLibrary('test.exe');//直接载入文件WRes:=FindResource(WriteIcoEXE,PChar(1), RT_ICON); //从WriteIcoEXE中查找PE图标资源..................end;另外给老师们再看看下面代码,下面代码是用流把资源保存成test.exe文件,这运行是没问题的.保存下来的文件也是有图标可运行的.var WriteIcoEXE,MeIcoRes:THANDLE;IcoFileStream:Tmemorystream;lpMemointer;beginIcoFileStream:=Tmemorystream.Create;MeIcoRes := FindResource(HInstance,'EXE','exefile');//查找自身资源文件中叫EXE的资源.lpMem:=LockResource(LoadResource(HInstance,MeIcoRes)); //锁定资源IcoFileStream.WriteBuffer(lpMem^,sizeofResource(HInstance,MeIcoRes)); //把EXE资源写入内存流IcoFileStream.SaveToFile('test.exe');//把内存流保存成文件..................end;