views:

49

answers:

5

Where should I store the application installation folder for application to reffer ?

+3  A: 

I believe what you're looking for is the GetModuleFileName function, which you can use like so:

// get the full path to the current executable
wchar_t fullPath[MAX_PATH];
GetModuleFileName(NULL, fullPath, MAX_PATH);

// cut the string at the last slash, because we just want the directory
// not the actual executeable file name. 
TCHAR *lastSlash = wcsrchr(fullPath, L'\\');
lastSlash = 0;

// directory where the executable is location is fullPath

This will work regardless of the current working directory and in general, this is how I do all "relative path" stuff (that is, I never actually use relative paths, they're always absolute paths, based off the value returned from the function above).

Dean Harding
Note that this is where you were launched from, not where your app was installed to. They _should_ of course be the same...
MSalters
+1 for using the Unicode functions. But it must be `*lastSlash = 0`, and you should test whether the search for the slash was successful. Also consider using a `wstring` object instead of the C array.
Philipp
+1  A: 

You can use the registry for storing installation folders.

ckv
A: 

::GetModuleFileName(NULL, out_lpPathName, in_size) will give you full path of your executable file.

Alexander
A: 

ApplicationData folder, even not admin access can help to access you install data. use SHGetSpecialFolderPath with CISDL CSIDL_APPDATA

thatsalok
A: 

In the registry. To be specific, under HKEY_LOCAL_MACHINE\SOFTWARE\YourCompanyName\YourApplicationName\ if you installed your app for all users (i.e. in \Program Files), and under HKEY_CURRENT_USER\SOFTWARE\YourCompanyName\YourApplicationName\ if you installed it for a single user only.

MSalters