I am currently hard-coding the path to my application as follows:
const char* OriginCopyFile = "C:\\Program Files (x86)\\i-cut\\i-cut\\Origin_copy.txt";
This application is going to be running in both 32 and 64 systems. How can I detect the path without the file name in order to reuse it with several files and make it portable between architecture.
You can use GetModuleFileName to get the path to your executable, wherever it was installed or even moved later. You can then PathRemoveFileSpec to remove the executable name (or strchr()
and friends if you want to support earlier versions than Windows 2000).
SHGetSpecialFolderPath(CSIDL_PROGRAM_FILES)
will at least give the path to the program files directory. You'll have to deal with adding the rest of the path and file name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With