Re: set current worlking directory to executable path



In windows environment path is set to executable path. it seems that there is no libpng.dll found in my 
system so the images dont load, [anyway i am not going to check whether the pixmap has loaded or not]

and GetModuleFileName() alone is enough to get the executable path.
 
thank you Lillqvist for your help,

Tor Lillqvist <tml iki fi> wrote:
Yogesh M writes:
I am using Gtk in windows(as well as linux). I want to set the
environment path to executable path so i can load icons present in
the executable path. I will be happy if it works both on linux and
windows.

On Linux, do a readlink on /proc/self/exe (if it exists), and
g_get_dirname() on the result.

On other Unixes, don't know. Some might have something like
/proc/self/exe. Otherwise look at argv[0], and if it doesn't contain a
directory already (possibly relative) look for the executable in
$PATH, etc. Note that this method is trivial to spoof, so it shouldn't
be used for anything that might have security consequences.

On Windows, do GetModuleFileName() on the result of
GetModuleHandle(NULL). If you want to be really correct, use the wide
character version (and then convert pathname from UTF-16 to UTF-8
before passing to g_open() etc.)

--tml


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]