How I Compile Resources into my Application and Access them?

后端 未结 2 385
故里飘歌
故里飘歌 2021-01-13 17:41

How can I make a single executable package that contains DLL and Image Resource Files?

Then how do I extract them from my Executable at Runtime?

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 18:12

    What I've found out to be convenient, is to use a .zip container.

    Then you'll have two implementations:

    1. Append some .zip content to an existing .exe, and the .exe code will retrieve the .zip content on request;

    2. Embed the .zip content as a resource, then extract on request each content.

    Solution 1 will add the .zip content after compilation. Whereas 2 will add the .zip content at compilation. For a setup program, I think solution 1 makes sense to me. For a way of retrieving some needed files (libraries, and even bitmaps or text) which are linked to a particular exe release, solution 2 could be envisaged.

    Using .zip as format make it easy to parse the content, and allow compression. Using a tool like TotalCommander, you can even read the .zip file content with Ctrl+PgDown over the .exe. Very convenient.

    You'll find in this link how you implement solution 1, and in this link (same page, but another post) how to use the TZipRead.Create() constructor to directly access to a .zip bundled as resource. You'll find in our repository how it works with working applications: e.g. how we embedded icons, textual content and graphviz + spell-checker libraries in the SynProject executable.

    About performance, there is no difference between the two solutions, at least with our code. Both use memory mapped files to access the content, so it will be more or less identical: very fast.

提交回复
热议问题