Last active
January 15, 2017 11:28
-
-
Save ccy/9568100bb105da07f24ccc745d2c549b to your computer and use it in GitHub Desktop.
Update embedded resource in Windows binary file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure UpdateExeResource(Const Source,Dest:string); | |
var | |
Stream : TFileStream; | |
hDestRes : THANDLE; | |
lpData : Pointer; | |
cbData : DWORD; | |
begin | |
Stream := TFileStream.Create(Source,fmOpenRead or fmShareDenyNone); | |
try | |
Stream.Seek(0, soFromBeginning); | |
cbData:=Stream.Size; | |
if cbData>0 then | |
begin | |
GetMem(lpData,cbData); | |
try | |
Stream.Read(lpData^, cbData); | |
hDestRes:= BeginUpdateResource(PChar(Dest), False); | |
if hDestRes <> 0 then | |
if UpdateResource(hDestRes, RT_RCDATA,'DATA',0,lpData,cbData) then | |
begin | |
if not EndUpdateResource(hDestRes,FALSE) then RaiseLastOSError | |
end | |
else | |
RaiseLastOSError | |
else | |
RaiseLastOSError; | |
finally | |
FreeMem(lpData); | |
end; | |
end; | |
finally | |
Stream.Free; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment