Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a simple Program Files/Program Files (x86) directive for C++ in windows?

Tags:

c++

path

windows

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.

like image 383
Peretz Avatar asked Dec 01 '11 21:12

Peretz


2 Answers

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).

like image 151
kichik Avatar answered Oct 19 '22 14:10

kichik


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.

like image 26
Jerry Coffin Avatar answered Oct 19 '22 14:10

Jerry Coffin