[comp.sys.atari.st] GEM messages --- longer messages

haacke@exunido.uucp (Ralf Haacke) (10/25/89)

>Hello,
>	Has anyone ever managed to send a message to a desk accessory in GEM?
>It always bombs out whenever I send a message to any but the process that is
>sending the message ( the ap_id returned by appl_open() ).
>
>   E.G.
>		:
>	ap_wid = appl_find("MYACC   ");			/* This bit works */
>	gets(message);					/* Unimportant */
>	appl_write(ap_wid,strlen(message),message);	/* This crashes */
>		:
>
>However if appl_find is given the name of the current process then this
>code works fine.
>
>It is not the desk accessory that is at fault as it works perfectly with system
>messages sent by the AES.
>
>Anyone tried anything similar at any time?
>
--------------------------------------------------------------------------------

In the first three WORD of a GEM message must be present 'internal message-id',
'GEM-id of the sender' and 'length of the "full" message - 16'.

For your PROGRAM:
	int	appl_id;	/* Application-id */
	int	msg[100];
		:
	ap_wid = appl_find("MYACC   ");
	gets(message);

	/* Thas new !!! */
	msg[0] = 1024;  		/* internal message-id */
	msg[1] = appl_id;		/* I'm sending this message */
	msg[2] = strlen(message)-10;	/* add 6 for administration-bytes (0..2)
					   sub 16 for bytes in msg-buffer     */
	msg[2] = msg[2]<0 ? 0 : msg[2]; /* No negativ numbers !!!!!           */
	strcpy((char*)&msg[3], message);

	/* And now your program */
	appl_write(ap_win,msg[2]+16,msg);
	evnt_timer (1000,0);		/* Wait a moment for the accessory to
					   receive the message */
		:


The ACCESSORY:
	int	msg[8];
	char	out[200];
		:
	evnt_mesag(msg);		/* get a message */
	if (msg[2] != 0)		/* more then 16 Bytes transfered */
	{
					/* save the first bytes (WORD:3..8) */
		memcpy(out, (char*)&msg[3], 10);
					/* add the rest of the message */
		appl_read(acc_id,msg[2],&out[10]);
					/* end the string */
		out[10+msg[2]] = '\0';
		puts(out);
	}
		:


I hope this can help you.

Dieter

--------------------------------------------------------------------------------
| Dieter Fiebelkorn                               | With a rubber duck,    :-{ |
| fiebelko@gandalf.irb.informatik.uni-dortmund.de | one's never alone.     :^} |
--------------------------------------------------------------------------------