lotus



previous page: 4.12) How do I set what folder should initially be shown in the SFGetFile boxes? (Files - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 4.14) When can I use those nifty, easy to use FSSpec calls? (Files - Mac Programming)

4.13) How do I find the folder my application started from? How do I find the application file that's running? (Files - Mac Programming)




Description

This article is from the Mac Programming FAQ, by Jon Watte h+@austin.metrowerks.com with numerous contributions by others.

4.13) How do I find the folder my application started from? How do I find the application file that's running? (Files - Mac Programming)

Under System 7, you call GetProcessInformation using the
ProcessSerialNumber kCurrentProcess with a pointer to an existing FSSpec
in the parameter block. This will give you your file, and, by using the
vRefNum and parID, the folder the application is in.

*code*
OSErr   CurrentProcessLocation(FSSpec *applicationSpec)
{
    ProcessSerialNumber currentPSN;
    ProcessInfoRec info;
    
    currentPSN.highLongOfPSN = 0;
    currentPSN.lowLongOfPSN = kCurrentProcess;
    info.processInfoLength = sizeof(ProcessInfoRec);
    info.processName = NULL;
    info.processAppSpec = applicationSpec;
    return ( GetProcessInformation(¤tPSN, &info) );
}
*end*

Beware from writing to your applications resource or data forks; the
former breaks on CDs/write protected floppies/file servers/virus
checkers, the latter fails on PowerPC as well as in the above cases.

 

Continue to:















TOP
previous page: 4.12) How do I set what folder should initially be shown in the SFGetFile boxes? (Files - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 4.14) When can I use those nifty, easy to use FSSpec calls? (Files - Mac Programming)