delphi - 将流写入 RCDATA 资源

标签 delphi resources stream

在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/

相关文章:

c# - 如何将字符串转换为流?

mysql - 无法从 delpi Xe5 TSqlConnection 连接到 Mysql 数据库

multithreading - tcriticalsection.create 的访问冲突

c# - ResourceSet 不加载子文件夹的子文件夹中的项目

javascript - JavaScript 不调用函数

macos - 在 Swift 中逐行读取文件/URL

Delphi7,创建组合框项目

Delphi Prism Cirrus 访问和设置函数的结果

php - 我可以通过取消设置句柄来关闭文件吗?

android - Android App Dev:关于如何编码来自远程ftp服务器的文件的音频流的任何示例/建议?