gpt4 book ai didi

c++ - 如何将数据存储在 C++ 可执行文件的资源部分?

转载 作者:行者123 更新时间:2023-11-28 07:54:27 25 4
gpt4 key购买 nike

我正在努力寻找有关如何使用可执行文件中的资源部分来存储和检索数据的任何有用资源。

如果有人愿意解释它并可能提供一些示例代码,我将不胜感激。

编辑 - 使用 Windows Visual c++ 2008。

最佳答案

有一种可移植的方法可以在可执行文件中对文件进行编码:以特定结构对文件进行编码。例如:

// header MyFile.h
static const int fileSizeInBytes = 42;
extern const unsigned char myFileContents[fileSizeInBytes];

// source MyFile.cpp
const unsigned char myFileContents[fileSizeInBytes] =
{
0x0A, 0x35, 0x25, //...
// ...
0xAB, 0xCD, 0xEF
};

您可以找到一些自动生成这些文件的工具(例如,对于 Qt,有 rcc)。

此外,还有一个 more specific answer here ( window ,PE 格式)。您也可以look here (虽然是针对Irrlicht Engine的,但是代码比较清晰小巧,容易理解)(仍然是PE格式)。我不知道 ELF 格式。

关于c++ - 如何将数据存储在 C++ 可执行文件的资源部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13056517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com