Add graphics to executable without resource rc file.

Using C++11 on a Microsoft Windows operating system that is 32 bit and compiling with Code::Blocks 17.12 .

I have been reading about using a resource file. I think that they can be read and changed after the program is compiled.

I want to be able to include a bitmap in my executable without using a resource file.

Currently I do similar to this:



I place in my resource.h file

#define IDB_ORANGE_BALL_001 1001



in the resource.rc file.

#include <windows.h>
#include "resource.h"
IDB_ORANGE_BALL_001 BITMAP "OrangeBall.bmp"



in some other header file I use

Test_Image = LoadBitmap(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDB_ORANGE_BALL_001));



But now I have read that the "OrangeBall.bmp" can be read from my resource.rc file, and maybe more.

I do not want that. I want to compile the OrangeBall.bmp into the executable.


Please help.

Thank you.
You can create arbitrary byte arrays and include any data you want.
1
2
const std::uint8_t orange_ball[] = { /*...*/ };
const size_t orange_ball_size = sizeof(orange_ball);
Needless to say, bundling your data in this manner would just be a slightly bigger inconvenience for someone like me, if I wanted to look at your assets. So my question to you is, how much effort are you willing to put in to prevent others from extracting your assets?
I have been reading about using a resource file. I think that they can be read and changed after the program is compiled.

Nope. Resources are compiled and linked into the app's executable when using a resource script file. Changing a resource script after you've created an exe won't change anything in the exe.

I want to compile the OrangeBall.bmp into the executable.

Then use a resource script file. Manually loading a bitmap as an external file using LoadBitmap (or LoadImage) at runtime reduces the size of the exe, as well as creating the possibility the file can't be found when trying to load it.

As helios points out it is possible to mash resources into an exe without a resource script. Using a resource script makes it easier.

A resource script doesn't contain the actual file itself. It just describes the particulars about the resource.
https://docs.microsoft.com/en-us/windows/win32/menurc/about-resource-files

Whatever you've been reading either you are not understanding it or it is seriously flawed. And wrong.

LoadBitmap is used specifically to load a resource from an app's executable. To load an image resource from either the exe or from an external file use LoadImage.
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadbitmapa
I tried to reply to helios but I did not see any button to reply to that posting. I just see a general reply button at the bottom of the page for the original question.

What am I missing for this?

Thank you both for your help. I am studying your answers now.

I did not see any button to reply to that posting. I just see a general reply button at the bottom of the page for the original question.
That's how forums work.
helios, thank you.

I looked up const std::uint8_t and also std::uint8_t . I think that you might mean to convert the bitmap binary into a format that I can embed into my code and use it that way. I am not certain about that. I am studying this.

Needless to say, bundling your data in this manner would just be a slightly bigger inconvenience for someone like me, if I wanted to look at your assets.

I do not know what that means. I thought that compiled C++11 code was uncompilable except in vague generalities and guessings. Your comment seems to suggest otherwise. I still want to know how to include a bitmap in my exe without using any resource file for that.

My bitmap might be 64 pixels by 64 pixels and full color. That seems to be small and I expect it to not take up much room in the exe if I could compile it in there.

Thank you helios.


Last edited on
furry guy, thank you.

Nope. Resources are compiled and linked into the app's executable when using a resource script file. Changing a resource script after you've created an exe won't change anything in the exe.


Does that mean that if I have a bitmap of an orange ball that I (use?) from the resource file then if I compile the program and release it to the general public, that someone can not change that to a bitmap of a blue triangle?

I have read a lot of comments elsewhere, but none of them seem to have specifically informed me that this can be done or can not be done.

As helios points out it is possible to mash resources into an exe without a resource script.

Ok. I am still studying and trying to understand what he said.

I can load other images from exterior files. I want this one image to be unchangeable inside of the executable.


I read from stackoverflow
another reason in my opinion, any one can open your executable and explore your resources and may edit it, change properties!! I want it to be hidden – ahmedsafan86
I do not fully understand that, but it does not sound like what I want. They were talking about dialogs and creating custom windows, which is not what I am interested in here. The part of someone being to manipulate the resources file is bothersome.


Using a resource script makes it easier.

I used to be triple chin extra fat. It was easy to keep eating. Combined with pain and/or discomfort I lost a lot of weight. No drugs. Much less eating. Easy did not work. I understand the concept, thus I am here asking of the learned like you how this is done.

Thank you furry guy.





Last edited on
I thought that compiled C++11 code was uncompilable except in vague generalities and guessings.
That's not entirely correct, but it doesn't matter. We're not talking about compiled code, we're talking about a file included verbatim in the executable. I can open your executable in a hex editor and look for common byte sequences, such as a BMP, JPEG, or PNG header. I could do something more sophisticated, like hook common Windows functions, inspect video memory, etc. If I really want to extract your assets, I'm going to get them. Hence why I asked: how effort do you want to put in?

I want this one image to be unchangeable inside of the executable.
That's impossible.
Last edited on
helios, thank you so much. (so very much)

If you can see all that stuff, can you change it in a C++ compiled exe? To extract and read the images is not the question, though I am highly appreciative of your telling me that. To change them in an already compiled exe is my concern.

If I use a resource file as I described in my original question, and if I then compile the exe with this, can the image be changed inside of the executable by someone at least at your level of coding?



Please advise further.

Thank you helios.
Last edited on
There's nothing you can do to prevent someone else from modifying their local copy of your program however they please. That includes your executable code, any files you've included in the program, or anything else.
helios, thank you.

That is not a problem. I can change an *.exe to a *.txt and then edit the file and then change the *.txt to a *.exe, and try to run a program, but I do not expect that to work. Or am I wrong in that?

I am wondering if (inside of the *.exe) they can change a bitmap as I described originally to some other bitmap and make the exe work with the new bitmap. I want (inside of the *.exe) the orange ball image to stay an orange ball image and not become a blue triangle image. Can that be done? How?

What I said above implies that the program continues to work despite the modifications, so:
I am wondering if (inside of the *.exe) they can change a bitmap as I described originally to some other bitmap and make the exe work with the new bitmap.
Yes, this is perfectly possible.
helios, thank you.

It looks like I might build the bitmap from scratch (pixel by pixel) to a back buffer in the code. That way it is almost impossible to change the internal image from an orange ball to a blue triangle, except by God or Christians of great faith or angels, or maybe a brute force change of the binary executable, etc.

That seems to be close to the answer to my question.

I got my answer sufficient for now. Thank you.

Topic archived. No new replies allowed.