G
G
German2018-06-09 14:19:02
C++ / C#
German, 2018-06-09 14:19:02

How to package a file into a project and then extract it in C++ in Visual Studio?

I want to add a picture (.bmp 1280x1024 or 800x600) so that when the .exe file is launched, it will be unpacked to the C drive and the .exe will be able to work with it.
How to add it to .exe?
I would be very happy if you explain, and do not throw a link to a site with heaps of useless code without explanation.
Explain like a fool, thanks.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2018-06-09
@res2001

This is done with resources. The last time I worked with resources was 3 years ago - with a text file.
Create a resource description file (.rc) in the studio, add your file there. I won't say what specific buttons to press.
Then, in code, use the FindResource and LoadResource WinAPI functions to load the resource into memory as a byte array.
Then do whatever you want with it.
It makes no sense to save the file to disk, because. then again you will read from the disk.

M
Mercury13, 2018-06-09
@Mercury13

There are three ways to store a picture in an EXE file.
1. Bitmap resource. Uncompressed, most libraries allow you to load it in one line.
2. Binary resource. Any compression is possible, loading is written a little longer.
3. Array, const unsigned char picture[] = { };
I don't know what BMP library you are working with, and you have to look at the place.
And finally: why unpack it? Is it really necessary? (For example, I once needed to unpack pictures, because I didn’t want to write a graphics viewer and used the regular one.)
If necessary, then somewhere in a temporary directory, which must also be obtained first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question