closingcost
asked on
how to reference the executable directory
I have this program, sitting on Netware k:\abc\. When it runs, it needs to read in a file from the directory where the execuatable resides (so k:\abc\).
When a LAN user execute this program from their desk top, at c:\, they type -
k:\abc\theExe
How does theExe know to search the executable's directory instead of user's c:\? I know the following will NOT work -
FILE* = fopen("file.txt", "r"); //this look into the current working directory of the user - c:\
I know I can specify the \\server\path in my program. Is there any other ways?
When a LAN user execute this program from their desk top, at c:\, they type -
k:\abc\theExe
How does theExe know to search the executable's directory instead of user's c:\? I know the following will NOT work -
FILE* = fopen("file.txt", "r"); //this look into the current working directory of the user - c:\
I know I can specify the \\server\path in my program. Is there any other ways?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is true for non-command line programs as well. It works for Windows programs and (I believe--its been 10 years) for Mac as well.
ASKER
jhance,
I have tried the argv[0]. Seems that if I execuate from a different directory other than the one theEXE resides, and I put the theEXE's path in $PATH, argv[0] came out = what I typed at the command line, ie theEXE. The full path is not displayed. Is there a MFC function to get the path of the executable?
I'm writing code in VC++ 5.0. Program will be execuated by user from both NT/Win95 machine.
I have tried the argv[0]. Seems that if I execuate from a different directory other than the one theEXE resides, and I put the theEXE's path in $PATH, argv[0] came out = what I typed at the command line, ie theEXE. The full path is not displayed. Is there a MFC function to get the path of the executable?
I'm writing code in VC++ 5.0. Program will be execuated by user from both NT/Win95 machine.