AW: [Dev-C++] How to get application directory?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Josep S. <sub...@ar...> - 2004-03-09 18:12:09
|
>>in Win32 I get
>>the path to the running application like this:
>>
>>char szBuf[512];
>>GetModuleFileName(NULL, szBuf, 512);
>>
>>(if the call succeeded, szBuf now contains the full path to the current
>>module (executable))
Hi Paul,
Thanks alot for your hint! I'm a bit new to API and I don't know with c++ if
I have to declare this function (GetModuleFileName()) in a header or what I
do have to do in order to being able to use this function you describe.
Could you help me on that too? (If I need a function declaration in my
header, could you please post it with the right variable types or point me
to a website where i can find those API function declarations???)
Thanks again,
Josep
BTW,
I've tried with the following code, but I don't know if the *working
directory* is always, at the beginning, the same as the directory where the
.exe file lies!!!
const long size = 1000L;
char *buf;
char *cwd;
//size = pathconf(".", _PC_PATH_MAX);
cwd = getcwd(buf, (size_t)size) ;
char flag[size] = "--datadir=";
char *subdir = "\\data";
char *foo = strcat (buf, subdir);
strcat(flag, foo);
int argn = 3;
char *arg[] = {
argv[0], "c++", flag
};
mysql_server_init(argn, arg, (char **)server_groups);
-----Ursprungliche Nachricht-----
Von: dev...@li...
[mailto:dev...@li...]Im Auftrag von P.D.
van Zelst
Gesendet: Dienstag, 9. Marz 2004 17:33
Cc: dev...@li...
Betreff: RE: [Dev-C++] How to get application directory?
For the original poster: Don't know if it will help you, but in Win32 I get
the path to the running application like this:
char szBuf[512];
GetModuleFileName(NULL, szBuf, 512);
(if the call succeeded, szBuf now contains the full path to the current
module (executable))
To Per:
Thanks :D I forgot that lots of things are file (or pseudo-file) based in
Linux. But it appears that /proc/self/exe is a symlink to the current
binary... which brings me to a second problem: How do I get the target of a
symlink as a string or something :) Whenever I'm programming for Linux I
constantly run into problems, cause I have no clue where to get MSDN-like
information for Linux or POSIX.
Regards,
Paul
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Per
Westermark
Sent: Tuesday, March 09, 2004 1:14 PM
To: sub...@ar...
Cc: dev...@li...
Subject: Re: [Dev-C++] How to get application directory?
If the application was started with a path, you might retrieve it as
the arg[0] parameter of main().
If not, you have to search the path for an application with the correct
name. I don't think there is a standard function to perform this. If I'm
wrong, I very much want to know the name of the function, since it would
be useful :)
On Linux, it is possible to heck in the /proc filesystem. There exists a
symbolic link:
/proc/<process_id>/exe -> /my/running/binary
That will specify which binary that is running.
It may also be accessed as:
/proc/self/exe -> /my/running/binary
to avoid the extra trouble of retrieving process id and dynamically create
the path to the symbolic link.
/Per W
On Tue, 9 Mar 2004 sub...@ar... wrote:
> What I actually wanted is the directory where the binary application is
stored...
> Anybody knows how to get it?
>
> Thanks again,
> Josep
>
> ----- Original Nachricht ----
> Von: Per Westermark <pw...@ia...>
> An: Kevin Wood <ke...@me...>
> Datum: 09.03.2004 10:28
> Betreff: Re: [Dev-C++] How to get application directory?
>
> > The question was which directory the application is running in - not
where
> > the application binary is stored.
> >
> > /Per W
> >
> > On Tue, 9 Mar 2004, Kevin Wood wrote:
> >
> > > getcwd() returns the current working directory, which is not
necessarily
> > > the same as the directory in which the application resides.
> > >
> > > At 08:10 09/03/04, Per Westermark wrote:
> > > >getcwd() or _getcwd().
> > > >
> > > >/Per W
> > > >
> > > >On Tue, 9 Mar 2004, Josep Subirana wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > Do you know how to get the directory where your c++ application is
> > running
> > > > > in?
> > > > > This should be a simple question for most experienced c++
> > programmers!
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Josep
> > > > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.Net email is sponsored by: IBM Linux Tutorials
> > > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > > GenToo technologies. Learn everything from fundamentals to system
> > > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux Tutorials
> > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > GenToo technologies. Learn everything from fundamentals to system
> > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
>
>
>
>
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|