Some Noob Help

I am still very new to learning C++. I am trying to write a small program to help me at work. The program is to copy some files to a computer. I have one done already that works but requires the program to be in a folder with another folder containing the files being copied to the computer. I would like to include the files in the exe instead. That way it is just the program with everything in it. I am having the hardest time finding answers. The needed files are broken into several folders that need to be copied to the computer as well as an exe and inf in the main folder.

If anyone has any suggestions that can help me include them in the exe and point to them in my code I would greatly appreciate the help.

I have been writing in Visual Studio.

Thanks,
Vendetto
Hello Vendetto,

Just in case:

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



Post the code that you have or the program that does work so everyone can see what you have tried and can suggest what could be done.

I have done a little bit of this in the past, but first it would help to know where the program resides and how you are starting it.

Andy
The way to store files in an .exe on windows is to use resource files.
However this is not sth. for beginners since the windows api is anything then easy to use. If you want to try have a look at this tutorial, it show how to embed an icon in the .exe but embedding text files is not so different.
http://www.winprog.org/tutorial/resources.html
An even more complicated article
https://www.codeproject.com/Articles/19514/XResFile-Files-Stored-in-Resources-Part-1-Text-and
its ugly but you can embed the files in a program as hard coded data esp if the files are small. This is a terrible approach for most things.

a better approach, why not use a zip utility that makes a self extracting exe targeting the correct path/folder or user choice target path? That already exists, and the compressed files are at most the original size, usually 80% or less of it if not an already compressed format (audio/video/image/etc are usually already compressed and won't shrink).

or you can make your own self extracting archive format easily enough. you just need a way to know the path/filename and size of each chunk of data and where those chunks are. You may have to make a system call to create the folders.
Last edited on
Here is the code that I first used which requires the files being copied to the computer to be in a folder called MPFiles in the same folder as the exe Alter_MP_Folders.exe.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Alter_MP_Folders.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <cstring>
#include <fstream>
#include <io.h>
#include <cstdlib>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#include <Windows.h>
#include <ConsoleColor.h>
using namespace std;

int main()
{

	CONSOLE_FONT_INFOEX cfi;
	cfi.cbSize = sizeof(cfi);
	cfi.nFont = 0;
	cfi.dwFontSize.X = 0;                   // Width of each character in the font
	cfi.dwFontSize.Y = 24;                  // Height
	cfi.FontFamily = FF_DONTCARE;
	cfi.FontWeight = FW_BOLD;
	wcscpy_s(cfi.FaceName, L"Concolas"); // Choose your font
	SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);

	

	cout << red << endl << endl << "   Altering Media Player Folders... Please wait..." << green << endl << endl << endl << endl;

	Sleep(2000);

	system("cls");

	system("rmdir /s /q C:\\synergyii\\cddefaultcontents");

	
	system("rmdir /s /q C:\\synergyii\\h264cddefaultcontents");


	system("rmdir /s /q C:\\synergyii\\mediaplayer");

	system("xcopy /e /i /q /y  \"%CD%\\MPFiles\\*\" \"C:\\synergyii\\cdDefaultContents\"");
	Sleep(2000);
	system("xcopy /e /i /q /y \"%CD%\\MPFiles\\*\" \"C:\\synergyii\\h264cdDefaultContents\"");
	Sleep(2000);
	system("xcopy /e /i /q /y \"%CD%\\MPFiles\\*\" \"C:\\synergyii\\mediaplayer\"");
	Sleep(2000);



	cout << white << endl << endl << "   Process Completed!" << white << endl << endl << endl << endl;

	Sleep(3000);

	
	return 0;
}



15 lines of includes, 30 lines to set the font, 10 lines of a dos batch file, and a sleep :P
#include <dos.h> ///seriously? this still exists??

where do you want to take it from here?
Last edited on
jonnin, that's not a bad idea except the files have to go in 3 separate folders after the old ones are deleted. The files are created by one of our company programmers and I want to make an easy way to erase and install them on our customer computers with them being all contained into one exe.

I know I know it's not elegant but I am just trying to learn. I bet several of those headers aren't needed but like I said I am very new.
Look at tools that produce installers my friend. There are a couple of lightweight, simple ones that can bundled the files up and do what you need without any real work on your part.

Maybe someone has a 2020 suggestion for a good simple one? My line of work does not do this and the last one I used was probably in 2005 or earlier.

Trying to code this yourself is aggravating. Its doable, but its more work than is worth doing given that someone already did it. If you just want to code at it, we can come up with something, I think... but you are looking at a much bigger program than your glorified batch file.

I am not trying to be mean. I was just kind of jokingly saying you don't have anything like what you asked for in your first cut. What you want and what you have are not remotely similar, unfortunately.

https://helpdeskgeek.com/free-tools-review/4-tools-to-create-windows-installer-packages/
Last edited on
Why are you so concerned with packaging data within an executable?
It might not be a necessary step.

Small files can be embedded in generated source code. xxd has traditionally been the code generator of choice.
https://linux.die.net/man/1/xxd
This works well for small files, but C++ compilers will start to struggle as the generated code grows in size.

It is also (most likely) possible to embed arbitrary data in an executable using the linker. I've done this before, but not with Microsoft's tool chain. Data embedded in this way doesn't pass through the compiler.
Last edited on
Jonnin, I'll take at look and see what I can find. I'm not offended. I know it's nothing like what I want to achieve. I mentioned before that I wrote that as a start. I may have bitten off more than I can chew. Just want to learn C++ so figured after doing a few simple things that printed out stuff and moved files around on my computer, I could try to tackle an issue I was facing.

Mbozzi, I am trying to simply the process for my customers. I wanted to be able to give them one program to run that did what I need it to do which would be similar to the batch commands I posted. Some get confused with the whole folder structure so if everything was in one deal then I could send it to them and say run the program and boom the new files are installed from them. It's something to simply delete the old folders and create them again with the new updated correct files.
I have been writing in Visual Studio

Windows has a basic installer already. Not the easiest to learn and work with, but you can integrate the process into Visual Studio with plugins.
https://docs.microsoft.com/en-us/windows/win32/msi/windows-installer-scripting-examples

Is the software you are modifying on a user's computer put there by an installer? Then you have to be doubly aware there may be registry entries that need to be changed/deleted. Simply deleting the app's current install location is not the only step.

Unless you want to potentially screw up the user's computer/registry.

Install scripts can make this less of a problem. I see installers used to upgrade software that report previous versions have to be uninstalled before installing the new updated version.

Several installers I've used have Windows create a restore point before doing the install. The registry is one of the key components to the Windows OS.
Last edited on
Furry Guy, no changes to the registry are done. The files are for a stand alone media player my company creates for our larger VMS. The files are exported to a disc or USB when incidents are exported from the main program so they have no function on the system.

I know this is a weird topic. I was able to do this in a batch file but like my first attempt with C++ that had to be in a folder structure to work. I was hoping I could learn some more and I can probably get there one day but for now I have to go back to the beginning and take it one step at a time in my learning process.

If anyone has any books, websites, etc to suggest to someone wanting to learn please feel free to share them with me.
C++17 has the <filesystem> library. That could make a directory based approach much easier. No need to 'hardcode' folders that could potentially cause the program to error out.

You could even allow for customization at the user end.

https://en.cppreference.com/w/cpp/filesystem

I'd still recommend doing this via an installer, treated as a patch. Far less likely to screw up a user's machine.

C++ is powerful. What you are proposing is using a tactical nuke to swat a fly IMO.
Hey everyone thanks for the help!! So I figured it out using the installer approach many of you recommended. I was even able to set it up in a way to if the files are ever changed, I can easily change them and recreate the program. Tested it several times so far and works great! Thanks again for the help!!
Topic archived. No new replies allowed.