Writing a stream to an RCDATA resource

In delphi, how do you write a MemoryStream for 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 sense of inadequacy, because I don’t even know where to start fixing it. Is anyone

+6
source share
1 answer

In the parameter lpData UpdateResource() you need to pass the value of the TMemoryStream.Memory property instead of the pointer to the TMemoryStream object, for example:

 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; 
+11
source

Source: https://habr.com/ru/post/917561/