加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 将流写入RCDATA资源

发布时间:2020-12-15 04:31:45 所属栏目:大数据 来源:网络整理
导读:在delphi中,如何将MemoryStream写入数据资源? procedure StringtoRes (filename:string; Inputstream: TMemoryStream);var hUpdate: THandle;begin hUpdate := BeginUpdateResource(PChar(filename),True); UpdateResource(hUpdate,RT_RCDATA,'ID',LANG_NEU
在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对象指针的值,例如:
procedure StringtoRes (const FileName: string; Inputstream: TMemoryStream); 
var 
  hUpdate: THandle; 
begin 
  hUpdate := BeginUpdateResource(PChar(FileName),True); 
  try
    UpdateResource(hUpdate,InputStream.Memory,InputStream.Size); 
  finally
    EndUpdateResource(hUpdate,False); 
  end;
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读