On Wed, Jul 05, 2000 at 11:54:40AM +0800, Eric wrote:
> my program A want to call another program B, and return back to A. I
> have tried to use sysAppLaunch, when at B, press the HOME button,
> cannnot return to program A, but when press once more, it quit program A
> and go to Launcher. can anyone tell me what's the problem?
Assuming program B is yours too, try using AppCallWithCommand()
instead of SysAppLaunch(). AppCallWithCommand() allows one program
(A) to start another program (B) with a custom launch code. When
program B quits (returns), control is returned to program A. You
define the launch code (any integer > 32767) and a parameter block
which can be used to exchange data between the applications.
For example, say program A (caller) has a form in which you enter two
integers. After pressing a button, it then calls program B (callee)
to add the two integers, which in turn returns the result to A. You
could do this with the following:
First, program A:
/*
* caller.c -- simple PalmPilot application to test calling another app.
*/
...
/*
* Launch codes and parameter blocks
*/
#define myAppLaunchCmdAdd 32768
typedef struct
{
Int *x ;
Int *y ;
Int *result ;
}
BinaryOpParams ;
typedef BinaryOpParams *BinaryOpParamsPtr ;
...
static Boolean
MainFormHandleEvent(EventPtr event)
{
Int n1, n2, sum ;
Boolean handled = false ;
switch (event->eType)
{
case ctlSelectEvent: /* A control button was pressed and released. */
switch (event->data.ctlEnter.controlID)
{
case MainCallButton:
ReadNumbers(&n1,&n2) ;
sum = CallAdd(&n1,&n2) ;
DisplaySum(sum) ;
handled = true ;
break ;
}
...
/*
* CallAdd -- call "Callee" application to add two ints
*/
Int
CallAdd(Int *n1, Int *n2)
{
Int result ;
BinaryOpParams params ;
params.x = n1 ;
params.y = n2 ;
params.result = &result ;
AppCallWithCommand('jvCE', myAppLaunchCmdAdd, ¶ms) ;
return result ;
}
And program B:
/*
* Callee.c -- simple PalmPilot application supporting custom launch codes
*/
...
/*
* Launch codes and parameter blocks
*/
#define myAppLaunchCmdAdd 32768
typedef struct
{
Int *x ;
Int *y ;
Int *result ;
}
BinaryOpParams ;
typedef BinaryOpParams *BinaryOpParamsPtr ;
...
/*
* PilotMain -- entry point into PalmPilot application
*/
DWord
PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
{
/* Handle action codes */
switch(cmd)
{
/* Normal Application Launch */
case sysAppLaunchCmdNormalLaunch:
StartupApp() ;
MainEventLoop() ;
ShutdownApp() ;
break ;
/* Custom Add Command */
case myAppLaunchCmdAdd:
HandleAddCmd((BinaryOpParamsPtr) cmdPBP) ;
break ;
}
return 0 ;
}
...
/*
* HandleAddCmd -- add two numbers passed in via Add custom launch code
*/
void
HandleAddCmd(BinaryOpParamsPtr params)
{
Int x, y ;
x = *(params->x) ;
y = *(params->y) ;
*(params->result) = x + y ;
return ;
}
> moreover, is it really cannot use globel veriable in the sun -program B?
Yes, but you can access data passed via the parameter block, as well
as data stored in resources or databases.
Hope this helps,
John
-------------------------------------------------------------------------
John Valdes Department of Astronomy & Astrophysics
[EMAIL PROTECTED] University of Chicago
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/