pem@cadnetix.COM (06/05/90)
[]
I'm having some trouble getting an ordinary (not sub-) launch to
work. I've done launching before, and in fact I stole big chunks of _launch
code from a working program to do this, but it's not working. (Thus I'm
throwing in the code I use to set up the launch stuff in case I messed
up subtly there.)
The manifestation is that I get just a beep and a quit when the
_Launch trap is executed; the launch pb is ok beforehand and the SetVol and
such have gone successfully. The symptom is the same when compiled and
run standalone as under the debugger. I'm a little confused why this isn't
working.
Think C (4.0) Source code follows; This is typed by hand from a printed
listing because our FastPath is down, so might have a typo or two; the
original code compiles and links with prototypes required and pointer
type checking using c-macprotos.h:
typedef struct
{
StringPtr name;
long memconf; /* long to zap the 'LC' bytes too */
} LAUNCHPB, *LAUNCHPTR;
typedef struct
{
/* Appl param block for single document */
int message;
int count;
short vref;
long ftype;
char vers;
char filler;
char namelen;
char name[31];
} APPPARM, *APPPARMPTR, **APPPARMHANDLE;
typedef struct mydata
{
struct fstuff
{
char vol[28];
long dir;
char name[32];
} app,doc;
OSTYPE doctype;
} MYDATA, *MYPTR, **MYHANDLE;
...
WDPBRec wdpb;
volumeparam vpb;
MYHANDLE myhandle;
Boolean debugging;
...
static OSErr dolaunch(StringPtr appname)
{
LAUNCHPB pb;
pb.name = appname;
pb.memconf = 0L;
asm {
LEA pb,A0
DC.W 0x19f2 ; _Launch
}
/* D0 is already the result */
/* [we never get here anyway--pem] */
}
main()
{
OSErr err;
int appvol,docvol;
int appwd, docwd;
APPPARMHANDLE aph;
DialogRecord dlg;
FInfo finfo;
... (more variables) ...
... (Standard initialization stuff) ...
/* Nifty trick from USENET to find if running from TC */
debugging = ! Count1Resources('CODE');
...
(Recover volume names, dir id's, and file names for app and document
from a resource; provide a dialog box to modify them or a "splash"
dialog to show that we're launching.)
...
/* Find the volumes named */
vpb.ioCompletion = 0L;
vpb.ioNamePtr = (StringPtr) &((**myhandle).app.vol);
vpb.ioVRefNum = 0;
vpb.ioVolIndex = -1;
err = PBGetVInfo((ParmBlkPtr) &vpb,0);
if (err != noErr)
PANIC("\pPBGetVInfo (app vname->num) failed");
appvol = vpb.ioVRefNum;
vpb.ioCompletion = 0L;
vpb.ioNamePtr = (StringPtr) &((**myhandle).doc.vol);
vpb.ioVRefNum = 0;
vpb.ioVolIndex = -1;
err = PBGetVInfo((ParmBlkPtr) &vpb,0);
if (err != noErr)
PANIC("\PBGetVInfo (doc vname->num) failed");
docvol = vpb.ioVRefNum;
/* Open WD's for the app and document */
wdpb.ioCompletion = 0L;
wdpb.ioNamePtr - 0L;
wdpb.ioVRefNum = appvol;
wdpb.ioWDProcID = 'ERIK';
wdpb.ioWDDirID = (**myhandle).app.dir;
err = PBOpenWD(&*wdpb,0);
if (err != noErr)
PANIC("\pPBOpenWD (app) failed");
appwd = wdpb.ioVRefNum;
/* Make the app's WD be the default (prep for launch) */
/* Moved up here when _launch was failing in case the WD
was getting cleaned up too quickly */
err = SetVol(0L,appwd);
if (err != noErr)
PANIC("\pSetVol failed");
wdpb.ioCompletion = 0L;
wdpb.ioNamePtr = 0L;
wdpb.ioVRefNum = docvol;
wdpb.ioWDProcID = 'ERIK';
wdpb.ioWDDirID = (**myhandle).doc.dir;
err = PBOpenWD(&wdpb,0);
if (err != noErr)
PANIC(\PBOpenWD (doc) failed");
docwd = wdpb.ioVRefNum;
/* Replace the finder parm handle with a new one */
SetHandleSize(AppParmhandle,sizeof(APPPARM));
if (MemErr != noErr)
{
if (!debugging)
PANIC("\pSetHandleSize failed");
}
else
{
aph = (APPPARMHANDLE) AppParmHandle;
(*aph)->message = appOpen;
(*aph)->count = 1;
(*aph)->vref = docwd;
(*aph)->ftype = (**myhandle).doctype;
(*aph)->vers = 0;
(*aph)->filler = 0;
(*aph)->namelen = (**myhandle).doc.name[0];
BlockMove((**myhandle).doc.name+1,(*aph)->name,
(**myhandle).doc.name[0]);
}
/* Clean up the window/dialog */
CloseDialog((DialogPtr) &dlg);
/* Make sure it's an application */
err = GetFInfo((StringPtr) ((**myhandle).app.name),0,&finfo);
if (finfo.fdType != 'APPL')
PANIC("\pFile isn't an APPL");
/* Do the launch */
err = dolaunch((StringPtr) ((**myhandle).app.name));
if (err != noErr)
PANIC("\pdolaunch failed");
/* These days, a successful _Launch might return anyway, but
all we need to do is ExitToShell then. */
}
Paul Meyer pem@cadnetix.COM
Daisy/Cadnetix Inc. (DAZIX) {uunet,boulder}!cadnetix!pem
5775 Flatirons Pkwy. GEnie P.MEYER CI$ 73627,1274 AoL LordKorath
Boulder, CO 80301 (303)444-8075x277