如何将二进制数据嵌入/链接到 Windows 模块中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2740164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:23:08  来源:igfitidea点击:

How to Embed/Link binary data into a Windows module

c++windowslinkerembedbinary-data

提问by CrimsonX

So I have a Visual Studio 2008 project which has a large amount of binary data that it is currently referencing. I would like to package the binary data much like you can do with C# by adding it as a "resource" and compiling it as a DLL.

所以我有一个 Visual Studio 2008 项目,它有大量当前正在引用的二进制数据。我想通过将二进制数据添加为“资源”并将其编译为 DLL 来像使用 C# 一样打包二进制数据。

Lets say all my data has an extension of ".data" and is currently being read from the visual studio project.

假设我的所有数据的扩展名为“.data”,并且当前正在从 Visual Studio 项目中读取。

Is there a way that you can compile or link the data into the .dll which it is calling?

有没有办法可以将数据编译或链接到它正在调用的 .dll 中?

I've looked at some of the google link for this and so far I haven't come up with anything - the only possible solution I've come up with is to use something like ResGen to create a .resources fileand then link it using AssemblyLinkerwith /Embed or /Link flags. I dont think it'd work properly though because I dont have text files to create the .resources files, but rather binary files themselves.

我已经查看了一些谷歌链接,到目前为止我还没有想出任何东西 - 我想出的唯一可能的解决方案是使用类似ResGen 的东西来创建一个 .resources 文件,然后链接它使用带有 /Embed 或 /Link 标志的AssemblyLinker。我不认为它会正常工作,因为我没有文本文件来创建 .resources 文件,而是二进制文件本身。

Any advice?

有什么建议吗?

采纳答案by Robert

  1. Right click the resource script (.rc file)
  2. Choose Import
  1. 右键单击资源脚本(.rc 文件)
  2. 选择导入

http://msdn.microsoft.com/en-us/library/saced6x2.aspx

http://msdn.microsoft.com/en-us/library/saced6x2.aspx

You can embed any "custom" file you want, as well as things like .bmps and stuff VisualStudio "knows" how to edit. Then you can access them with your framework's resource functions like FindResourceLoadResourceetc...

您可以嵌入所需的任何“自定义”文件,以及 .bmps 和 VisualStudio“知道”如何编辑的内容。然后你可以使用你的框架的资源函数来访问它们,比如FindResource LoadResource等......

If you don't have a resource script.

如果您没有资源脚本。

  1. Click Project
  2. Add New Item
  3. Resource Script
  1. 点击项目
  2. 添加新项目
  3. 资源脚本

http://msdn.microsoft.com/en-us/library/sxdy04be(v=VS.71).aspx

http://msdn.microsoft.com/en-us/library/sxdy04be(v=VS.71).aspx

回答by renick

You can embed the binary data as a C language array - no resources involved at all. An old classic trick. see for example XD

您可以将二进制数据嵌入为 C 语言数组 - 根本不涉及资源。一个古老的经典技巧。见例如XD