从 exe 中检索资源文​​件

发布于 2024-08-24 00:48:23 字数 317 浏览 4 评论 0原文

我正在使用 Visual C++ 2008 包装文件,我已经弄清楚如何嵌入它们,但我不知道如何检索它们。我有一些 C++ 经验,但没有 Win32 或 Visual C++ 经验。包装的目标是运行一些代码,然后如果一切正常,它就可以运行嵌入的文件。

我包装了许多不同的文件,因此代码重用是关键,并且在所有情况下我都不知道嵌入文件的名称。但我可以将 exe 命名为与包装文件相同的名称,因此如果程序可以获得自身的名称,那么也可以工作。

一些打包的文件将是 exe,其他文件将是由外部程序运行的文件。

编辑:这些文件嵌入了 .res 文件,它们不仅仅是连接到 exe 的末尾。

I'm wrapping files with Visual C++ 2008, I've figured out how to embed them but I can't figure out how to retrieve them. I have some C++ experience, but none with Win32 or Visual C++. The goal of the wrapping is to run some code, and then if everything okay it can run the embedded file.

I'm wrapping many different files, so code reuse is key, and in all cases I won't know the name of the embedded file. But I could name the exe the same as the wrapped file, so if the program can get the name of itself that'd work too.

Some of the wrapped files will be exes, and the others will be files meant to be run by an external program.

Edit: These files are being embedded with a .res file, they're not just concatenated to the end of the exe.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿看小鸭子会跑 2024-08-31 00:48:23

那么您有一个作为资源嵌入到 EXE 中的二进制文件,并且您想要读取该文件?

尝试这样的事情(非常粗略,在 MSDN 上查找函数以获得正确的参数):

HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(id), type);
HGLOBAL hGlobal = LoadResource(NULL, hResource);
BYTE* pData = (BYTE*)LockResource(hGlobal);
int size = SizeofResource(NULL, hResource);
// ... do something with pData and size, eg write to disk ...
FreeResource(hGlobal); // done with data

您需要添加一些错误检查!

So you have a binary file embedded as a resource in an EXE, and you want to read the file?

Try something like this (very rough, look up functions on MSDN for proper parameters):

HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(id), type);
HGLOBAL hGlobal = LoadResource(NULL, hResource);
BYTE* pData = (BYTE*)LockResource(hGlobal);
int size = SizeofResource(NULL, hResource);
// ... do something with pData and size, eg write to disk ...
FreeResource(hGlobal); // done with data

You'll want to add some error checking in to that!

断舍离 2024-08-31 00:48:23

您需要了解的主要内容(应该存在于编译为 .res 文件的 .RC 文件中)是资源的名称。由此,您可以使用 FindResourceLoadResource 加载数据。显然,您会将该数据写入临时文件并执行该文件。

The main thing you need to know (which should be present in the .RC file that gets compiled to the .res file) is the name of the resource. From that, you can use FindResource, and LoadResource to load the data. You'll apparently write that data out to a temporary file and execute that file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文