In delphi, how do you write a MemoryStream to a data resource?
procedure StringtoRes (filename:string; Inputstream: TMemoryStream);
var
hUpdate: THandle;
begin
hUpdate := BeginUpdateResource(PChar(filename), True);
UpdateResource(hUpdate, RT_RCDATA, 'ID', LANG_NEUTRAL,InputStream,InputStream.Size);
EndUpdateResource(hUpdate,False);
end;
This code gives me an access violation and an intense feeling of inadequancy because I don't even know where to start fixing it. Does anyone?
In the lpData
parameter of UpdateResource()
, you need to pass the value of the TMemoryStream.Memory
property instead of the TMemoryStream
object pointer, eg:
procedure StringtoRes (const FileName: string; Inputstream: TMemoryStream);
var
hUpdate: THandle;
begin
hUpdate := BeginUpdateResource(PChar(FileName), True);
try
UpdateResource(hUpdate, RT_RCDATA, 'ID', LANG_NEUTRAL, InputStream.Memory, InputStream.Size);
finally
EndUpdateResource(hUpdate, False);
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With