[comp.sys.mac.programmer] Notification Manager Help Needed

mithomas@bsu-cs.bsu.edu (Michael Thomas Niehaus) (02/14/90)

Can someone help me out?  I wrote a routine that uses the Notification Manager
to notify users when errors occur in a program that I am working on (instead
of keeping track of whether I am in the foreground or background and dealing
with those cases).

This routine enqueues the NM request pointer, and a completion routine
removes a flag from the nmRefCon field to show that it is free to be used
again.  Fine and dandy.

When the program is running in the foreground everything works fine.
When the program is in the background, there are problems.  The first
notification shows up without any problem.  But the second crashes the
machines spectacularly.  What am I doing wrong?

The significant code follows:

pascal MyResponse(nmReqPtr)
NMRecPtr		nmReqPtr;
{
	NMRemove(nmReqPtr);
	nmReqPtr->nmRefCon = 0L;
}


PostMessage(passString)
StringPtr passString;
{
	EventRecord		theEvent;

	while ( gNote->nmRefCon == 1L )
	{
		SystemTask();
		WaitNextEvent(everyEvent,&theEvent,60,thePort->visRgn);
	}

	PtoCstr( (char *) passString );
	strcpy( gString, passString);
	CtoPstr( (char *) gString );

	gNote->qType = nmType;
	gNote->nmMark = 0L;
	gNote->nmSIcon = 0L;
	gNote->nmSound = (Handle) 0L;
	gNote->nmStr = (StringPtr) gString;
	gNote->nmResp = (ProcPtr) MyResponse;
	gNote->nmRefCon = 1L;
	NMInstall( gNote );
}

Memory for gString and gNote are allocation in the beginning of the program.
Basically, this routine wastes time until the nmRefCon flag has been cleared.
Any ideas as to why this might not work?

Please respond directly to me, since our incoming news is nonexistant because
of phone network problems. (When IU does get through, mail has priority.)

Thanks,
-Michael

-- 
Michael Niehaus        UUCP: <backbones>!{iuvax,pur-ee}!bsu-cs!mithomas
Apple Student Rep      ARPA:  mithomas@bsu-cs.bsu.edu
Ball State University  AppleLink: ST0374 (from UUCP: st0374@applelink.apple.com)