Mega Code Archive

 
Categories / Delphi / Files
 

Resources inside .exe files

Title: Resources inside .exe files Question: How to add/update & delete resources inside exe files. Answer: After a lot of digging and searching, I've found the way to add/update/delete resources inside exe files. This little snippet works great for small files, but for some currently unknown reason it screws up the exe file when you try to add a large resource on 1mb. If anyone know how to bypass this, please post a little note on how to do this! :) Uses Classes, Windows, SysUtils, Dialogs; Type TBuffer = Array[0..0] of Byte; PBuffer = ^TBuffer; Var FS : TFileStream; ResourceHandle : THandle; DataLength : DWord; Data : PBuffer; Ok : Boolean; Begin ResourceHandle := BeginUpdateResource(pChar('d:\someexefile.exe'), False); IF (ResourceHandle 0) Then Begin FS := TFileStream.Create('d:\somebitmap.bmp', fmOpenRead); FS.Seek(0, soFromBeginning); DataLength := FS.Size; GetMem(Data, DataLength); FS.Read(Data^, DataLength); FS.Free; Ok := True; IF (not UpdateResource(ResourceHandle, RT_RCDATA, pChar('MyNewResource'), LANG_SYSTEM_DEFAULT{MakeLangID(LANG_NEUTRAL, SUBLANG_NEUTRAL)}, Data, DataLength)) Then Ok := False; IF (not EndUpdateResource(ResourceHandle, False)) Then Ok := False; IF (Ok) Then ShowMessage('Update of resources successful!') Else ShowMessage('Update of resources failed!'); FreeMem(Data); End; End.