CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2018
    Posts
    19

    How to add resource files to executable in VS2017

    I want to add an image as resource file in .exe (want to embed image in .exe). The image should be inside the .exe. So when I run the .exe, the program can access and display the image. How do I tell the C++ program where the image is?

    I have noticed that games do not store all images inside the .exe but they tend to also store images outside. Why is this so? Is it costlier to store images inside .exe??? Can .exe be disassembled to get resource files inside it? So can I disassemble my .exe to get the image that I had embedded?

    Is embedding the image inside .exe the same as storing it outside? Or is it worse to embed?

    Side question (because I did not want to spam threads)

    When you compile and link source codes separately, can you use a function declared in a source on the other source? So if I declared "print()" in one of the codes, can I use print() in the other? Or do the source codes know absolutely nothing about each other? Can I make it so that they know?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to add resource files to executable in VS2017

    Use the resource manager inside VS to add a new resource. It will allow you to select a file and choose the resource. Once you have done this, you will be able to see the resource listed in the solution explorer. You right click on the resource, choose properties, and there will be a setting allowing you to mark it as an embedded resource. Be aware that my steps on how to do this are from memory and things change a bit with each Visual Studio version. It would be good to explore around and see what it has to offer.

    As to your embedding resources question... Embedding the resources directly into the exe has the advangtage of being self-contained (and fewer files to distribute). If you have a lot of resources, it can bloat the exe amd take it longer to startup. Also, if you embed the resources and need to update them, you'll need to recompile the exe. If the resource files are external, you add complexity, but you can manage them with a resource manager, which can pre-fetch and preload them, allow you to update them through an external service without having to recompile the exe, and other benefits.

  3. #3
    Join Date
    Nov 2018
    Posts
    19

    Re: How to add resource files to executable in VS2017

    Suppose I have added a text file to the resources folder. How do I read from this file?

    edit: I don't get it.. I'm only able to add .cpp and .h files to the resource file when I right click it..

    Where is the resource manager?
    Last edited by Numb; January 6th, 2019 at 09:46 PM.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to add resource files to executable in VS2017

    Quote Originally Posted by Numb View Post
    Suppose I have added a text file to the resources folder. How do I read from this file?

    edit: I don't get it.. I'm only able to add .cpp and .h files to the resource file when I right click it..

    Where is the resource manager?
    Are you familiar with the Visual Studio menu item called 'Help'? Have you tried typing in 'resource manager' in the help search? How about googling for "visual c++ resource manager"? Anything? How about googling for "how do I add a resource in visual c++ 2017"?

  5. #5
    Join Date
    Nov 2018
    Posts
    19

    Re: How to add resource files to executable in VS2017

    "Help" did not help at all
    https://docs.microsoft.com/en-us/sea...manager&scope=

    Googling for "visual c++ resource manager" did not help either
    https://www.google.com/search?client...source+manager

    Obviously I googled how to add resource file. But that gave me links that led to something about .resx and .rc files which by the way, I have no clue about. I even googled how to embed a textfile and that gave me even more complicated stuff. And that's why I came here!

    I would appreciate a link. Thanks.

    edits:
    I want to embed a text file and be able to read from it.

    I was able to click on "add resource" and import a .txt file. It gave me a file with weird data. I don't know how to use this..
    Last edited by Numb; January 7th, 2019 at 12:00 AM.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to add resource files to executable in VS2017

    An .rc file gets added when you create a new project with the Windows application or MFC template. Double-click on the file in the solution explorer and it will open in the resource view. From there, you can right click and add a resource where you can select a file, create a new resource or a custom resource.

    Check out the books that were recommended to you as it might be hard to find this information on the internet. The books may be for older Visual C++ versions, but the equivalent functionality should be available in VC 2017 - feel free to get to know the IDE.

    Btw, if you started a project from scratch, taking a look at the new projects I've mentioned above might help you figure out how to add resources to your project. Or, if you didn't start with one of the above templates, you may want to.

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to add resource files to executable in VS2017

    Quote Originally Posted by Numb View Post
    Obviously I googled how to add resource file. But that gave me links that led to something about .resx and .rc files which by the way, I have no clue about. I even googled how to embed a textfile and that gave me even more complicated stuff. And that's why I came here!
    There's no shortcut. You definitely have to get the knowledge enough to understand the concept prior to getting to "even more complicated stuff".

    As to embedding image to exe, try to review this post.

    BTW, Introduction to Resources.
    Last edited by Igor Vartanov; January 12th, 2019 at 04:18 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured