VS 2022 c++ application - writing an entry to a .rc file - c++

I have a c++ app where I use LoadString to read string entries from an embedded .rc file. Is there a way to write append/update string entries like a WriteString?
Looking for a way to write to a resource file within a c++ app

No, there is no such function. Programs are usually installed in places where the user running them does not have permission to change files - so the ability to change the actual executable is not something that's been requested very often.
I suggest that you store the information somewhere in the %AppData% directory or registry instead.

Related

Where can I put my SQLite database in my QT application if I can't put it in my resources?

Recently I was trying to put a SQLite database into a QT 5 application I'm writing. I want it to be universally accessible - that is on all systems regardless of where it's installed. I put it as a resource then found out that evidently you can't put databases in resources as the string for the database path passed to setDatabaseName doesn't get translated to the resource system so the database can't be found.
So where can I put it? I don't want to just put it at the root of the drive like C:\repo.db or D:\repo.db as many people hate files cluttering their root directories (like me). I was going to put it just in the source folder and access it as "repo.db" or as I tried "./resources/database/repo.db" but even QFile doesn't see that. Where can I put it and how to access it there? My settings file was going to be in my resources but I wasn't sure if I could update the file then. I need a place that is available from the moment the application is installed on any system including my own so that it can be accessed both while coding it and when it's built.
I'm not asking for opinions - I want a place that is not in the root, somewhere universal like the installation directory (but how do I find that with code?) or a settings directory (but how do I set that somewhere so I can find it later??)
For such purposes Qt provides a list of QStandardPaths functions that return platform specific standard paths, such as a path to desktop, temp directory etc.
For your particular case you might put your database in the directory that corresponds to the QStandardPaths::AppDataLocation key.
You can use QSettings to save path,settings and restore them.
QSettings m_Arhive("Company", "app_name");
//Set DB path
m_Arhive.setValue("DBPath", "c:/somewhere/database");
//Get DB path
m_Arhive.value("DBPath").toString()

Where to save a program's config and save files on Windows?

What directory is the typical place to save files generated by a program, like a game or tool, when the file itself isn't necessarily useful on it's own? (i.e it's not a "document" like a text file or image that you'd want easy access to, instead it's just a config or save file you'd want to tuck someplace out of the way)
Does this change depending on if a program is "installed", as opposed to an executable free-floating in a folder? (For instance, is it standard practice to just save in the same folder in the latter case?)
If it's someplace that varies, is there a utility function I have to call to get a string of the path?
Check the Known Folder IDs for a tip. Most likely, you want FOLDERID_LocalAppData. Use SHGetKnownFolderPath() to retrieve the folder location.
Usually, I give the users the ability for "install" or "portable", in the latter case the app files goes into a folder under the portable installation folder.

how to give a version to mdb files

I am using a .mdb file as a database for a dialog based application. For the each Release I want to give a version to the mdb file if there are more entries added. using C++ i want to read the version and display it in the application.
Can you please tell me if it is possible to give a version to mdb file ?
You can add a table to MDB and track releases there. If MDB should change release number automatically after some data changes, you can use Data Macro (this is for Access 2010+)
You can create a custom property:
db.CreateProperty("VersionId", dbText, "1.0.0")
then add this to the database, but there is no way to read this without opening the database file.
There is no easy way to do that and its probably best to do it as a db.property like #Gustav proposed.
If for some reason it is important to have a version information that you can read without opening the file as access file there are still some options:
There is the Windows Shell Property System that I think allows you to add Properties to every File/Folder.
You could change the Creation Date for the file to fit your need.
You could perhaps even read/change the file content itself in a binary stream if you research it thouroughly enough.
and you can of course have an external .txt (or .ver or whatever) file that you update automatically from the db.property whenever you open the db.

Xml file are saved in two different path

I created application that store some data to XML file. The issues is with the path of the XML saving. Am using TinyXML to save the data in vc++.
When I deploy this application, it installs in "C:\Program files(x86)\applicationname " and when I run the application the XML file is saving in
"C:\Users\UserName\AppData\Local\VirtualStore\Program Files (x86)\ApplicationName ".
I have made this application to work on system startup. So when I restart this application,
the xml file is stored in different path "C:\Users\UserName\AppData\Local\VirtualStore\windows\sysWOW64"
I want my XML to be stored in the path where I installed or should be stored in appdata, application name
What should I do to store XML file in one places where application is installed?
doc.SaveFile( "test.xml" ); // xml saving code in tinyxml library
Firstly, this has nothing to do with C++, as the C++ code is probably working. Same with XML and tinyxml and even visual-c++.
It seems that windows redirects those write accesses to a user-specific "VirtualStore\Program Files", but I'll leave it to you to research the actual semantics of that. On startup, when there is no user, this path obviously differs, since the former user is not logged in.
Now, in order to get a fixed path, you can use the function GetModuleFileName() to find out the location of your executable and use that path to locate Smartmeter.xml. However, the problem you are facing now is that programs installed under "Program Files" don't magically gain write access rights to their install directory. This is to protect one user from messing with data of another user.
I think that what you are doing is writing a program that runs in the background, which would be called a "service" under MS Windows. What is still unclear is what you want to achieve with this file and also what you are planning to do overall, and these are things that decide the future steps. In any case, take a look at the possibilities that services provide, maybe there is something that fits your needs.

Symbian C++ - Persistent storage of a single variable

I wish to store a single variable in my application that will be saved between runs. This will be a version number that will be used to trigger an update option and so will change only rarely.
Does anyone have suggestions on the best way of implementing this? Considering it's such a simple requirement I am interested in the simplest solution.
Thanks!
Normally, that sort of information will be held in a constant (not a variable) in the binary, and the binary will contact an external site to find out whether there is a more recent version of the software. When it downloads the new, the newly downloaded file will have a new constant embedded in it.
Alternatively, you could keep the information in some sort of file in the file system. I'm not familiar with the Symbian environment, but something similar most likely exists.
It has already been mentioned, so I am going to elaborate on it. Create a file in your project directory that will contain the version number. Make that file a part of final SIS file by adding a line about it in the PKG file---for example, put a line in the PKG file to tell the installer to copy the file to a place like c:\System\Apps\${AppName}\${filename} on the device. Within code, read the version number from that file. The advantage you will have from doing it this way is that when you update your code and edit the file in your project directory and recreate an updated SIS file, on updating the SIS on the device, the version file will automatically get replaced with the current one.