Link to home
Start Free TrialLog in
Avatar of closingcost
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?
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

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.
Avatar of closingcost

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.