且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将资源嵌入到单个可执行文件中?

更新时间:2023-02-16 14:50:13

Windows资源系统是这样工作的,所以如果你制作一个WinAPI或MFC应用程序,你可以使用这个。此外,Qt提供相同的功能,但在平***立的方式。他们只是将原始二进制格式的文件写入正常C ++文件中的字节数组,因此将它们作为数据编译到exe中。然后,它们提供访问这些数据块的功能像正常文件,虽然我不知道他们真的如何工作。可能是他们的文件类的一个特殊的实现,它只是访问那些字节数组变量。

The windows resource system works like this, so if you make a WinAPI or MFC application, you can use this. Also, Qt provides the same functionality, but in a platform independent way. They just write the files in raw binary format into a byte array in a normal C++ file, so they get compiled as data into the exe. Then they provide functions for accessing these data blocks like normal files, although I don't know how they really work. Probably a special implementation of their file class which just accesses those byte array variables.