从 exe 中检索资源文件
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么您有一个作为资源嵌入到 EXE 中的二进制文件,并且您想要读取该文件?
尝试这样的事情(非常粗略,在 MSDN 上查找函数以获得正确的参数):
您需要添加一些错误检查!
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):
You'll want to add some error checking in to that!
您需要了解的主要内容(应该存在于编译为 .res 文件的 .RC 文件中)是资源的名称。由此,您可以使用
FindResource
和LoadResource
加载数据。显然,您会将该数据写入临时文件并执行该文件。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
, andLoadResource
to load the data. You'll apparently write that data out to a temporary file and execute that file.