[comp.sys.mac.hypercard] Need help with a very simple XCMD

seiler@chrpserv.gsfc.nasa.gov (Ed Seiler) (01/25/90)

  I have a very simple example of an xcmd that I can't seem to get to work.
If I invoke the xcmd from the message box of the stack it is installed in,
and then "put the result", I get nothing. What am I doing wrong? I am using
Think C 3.01. It seems the basic mechanics of being able to return a string
work okay for another example if I call GetString(-16096) to get my Chooser
name, and then call PasToZero to convert it to a null-terminated string.
But trying to return a literal string as in the following example fails:

#include <MacTypes.h>
#include "HyperXCmd.h"
	
Handle CopyStrToHand(char *);

pascal void	main(paramPtr)
XCmdBlockPtr	paramPtr;

{
	paramPtr->returnValue = (Handle) CopyStrToHand("This is a test string");
}

Handle CopyStrToHand(str)
char	*str;
{
Handle	newHndl;
	newHndl = (Handle) NewHandle((long) strlen(str) + 1);
	strcpy((char *) (*newHndl), str);
	return(newHndl);
}

This seems ridiculously simple, but I can't figure it out.

Ed Seiler     seiler@chrpserv.gsfc.nasa.gov