在delphi中,如何将MemoryStream写入数据资源?
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;
这段代码给我带来了访问冲突和强烈的不足感,因为我什至不知道从哪里开始修复它。有人吗?
最佳答案
在UpdateResource()
的lpData
参数中,您需要传递TMemoryStream.Memory
属性的值,而不是 >TMemoryStream
对象指针,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;
关于delphi - 将流写入 RCDATA 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10939342/