ks3y+@andrew.cmu.edu (Kenneth L. Simons) (02/12/91)
I'm trying to write an XCMD that reads in parameters, calculates, and returns information periodically with "SendCardMessage." It sends messages (as Pascal strings) such as: MessageHandlerName "parameter" I am using Lightspeed C, with interface and glue routines taken from Gary Bond's book "XCMD's for HyperCard." I'm testing the XCMD in HyperCard 1.21. The XCMD's I construct this way sometimes seem to work fine, sometimes not. Trivial differences such as adding a few more variable declarations seem to make the difference between whether an XCMD works or fails. (HyperCard quits unexpectedly, or sometimes the computer hangs.) From trying different possible combinations of code, it seems (I'm not certain) that SendCardMessage causes the problem. I have heard a rumor that other people have had trouble with SendCardMessage. Does anybody know what the problem is and/or how to solve it? Thanks millions! Ken Simons. I list below a relevant piece of code which I think is fine, in case I'm overlooking some problem with it. I can send more extensive code if you want, but be warned that it's lengthy. /* Convert to a Pascal string & send to HyperCard card. */ void SendPascalCardMessage(paramPtr, str) XCmdBlockPtr paramPtr; char *str; { Str255 message; strcpy(message, str); ToPstr((char *) message); SendCardMessage(paramPtr, message); } /* The following routine comes from Gary Bond's book "XCMD's for HyperCard." */ /* This function converts a C string to a Pascal string. The C string is overwritten in the process. */ char *ToPstr(str) char *str; { unsigned char length, i; for (i = 0, length = 0; str[i] != 0; ++i) /* Find end of string */ ++length; while (i--) /* Shift string 1 byte to right */ str[i+1] = str[i]; str[0] = length; /* Put string length in 1st byte */ return(str); }