Click to See Complete Forum and Search --> : Executable Path
nordyj
April 9th, 1999, 11:45 AM
Can anybody tell me a good way to find the path of my executable? For example, if my program is located in D:\Manager\Manager\Debug\, is there a way to return the path name? I've looked through the documentation on the MSDN CD, and didn't find much. Thanks in advance.
Thomas Wiesinger
April 9th, 1999, 12:10 PM
A maybe acceptable solution I can shortly think of is ::GetCurrentDirectory(..),
but I guess this isn't 100 percent :)
Gomez Addams
April 9th, 1999, 12:22 PM
The problem with GetCurrentDirectory is that when one creates a shortcut
it is possible to start the executable in a directory other than where it resides.
GetModuleFileName should be able to do what you need.
Allen Yuh
April 9th, 1999, 12:29 PM
Use GetCommandLine() to retrieve the entire path for the program. But I found out that the string returned by the GetCommandLine() acts a little different:
If the program runs along, you will get the path, e.g.: "C:\Programs\Debug\myprog.exe" has extra '"' wrap the path. I guess the Win32 API wants to be able to display long directory names.
If the program is launched by other program, the path won't have the extra '"'.
You can try both cases to see the differences and watch out the '"'. Hope this will help. Good luck.
Someone corrects me, if I am wrong.
Allen
Thomas Wiesinger
April 9th, 1999, 12:29 PM
Hi!
Ofcourse you're right, that's what I ment with not 100 percent :)
Thanks,
Thomas
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.