At 2/2/2009 10:20 PM, you wrote:
>Hi.
>I guess GTK has a config file which is common across all the applications.
>Infact the library which i am wanting to write will be loaded by a GTK
>Application also.:)
>
>The applications will have their individual config files. In my case its has
>info about the location of the database which hold the application data. So
>a config file per exe is my basic requirement. I know it can be done by
>passing the path as an argument but if we could achieve the same by getting
>the location of the exe and fetching the config file from that location it
>would be useful learning exercise for me.TIA
You can still do what you want without explicitly passing the path as
an argument. I posted this earlier --
If I understand you correctly, you run the program from the root
directory thusly: /somedirectory/someother directory/myprogram
If that is correct, then argv[0] will contain the complete path to
the program, i.e. /somedirectory/someother directory/myprogram
If you strip off the program name, you will have the path to where
the program resides. So you get your config file from
/somedirectory/someother directory/myconfigfile
Won't this do what you need? Here is an example:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int found;
string myPath = string(argv[0]);
found = myPath.find_last_of("/\\");
myPath.resize(found);
cout << endl << "Running program from " << myPath << endl;
// system("PAUSE");
return EXIT_SUCCESS;
}
~Rick
[Non-text portions of this message have been removed]