home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
launch2.zip
/
LAUNCH.C
Wrap
C/C++ Source or Header
|
1993-10-16
|
3KB
|
104 lines
#define INCL_DOS
#define INCL_DOSERRORS
#include <os2.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct _SessionResult {
ULONG ulSessionID;
ULONG ulResultCode;
} SESSIONRESULT, *PSESSIONRESULT;
main (int argc, char *argv[])
{
int i;
ULONG retcode, idSession, pid, launched, background;
STARTDATA sd;
CHAR szObjBuffer[ CCHMAXPATH ];
CHAR szPgm[ 1024 ];
HQUEUE hq;
REQUESTDATA Request;
ULONG cbData;
PVOID pbuf;
BYTE priority;
static CHAR szQueueName[] = "\\QUEUES\\PGM1X2X3.MAG";
PSESSIONRESULT pSessionResult;
retcode = DosCreateQueue( &hq, QUE_FIFO | QUE_CONVERT_ADDRESS, szQueueName );
launched = 0;
if ( retcode ) {
printf( "DosCreateQueue failed: %d\n", retcode );
} else for ( i = 1; i < argc; i++ ) {
strcpy( szPgm, argv[i] );
sd.Length = sizeof( sd );
sd.Related = /* SSF_RELATED_INDEPENDENT */ SSF_RELATED_CHILD ;
sd.FgBg = SSF_FGBG_FORE;
sd.TraceOpt = SSF_TRACEOPT_NONE;
sd.PgmTitle = NULL;
sd.PgmName = szPgm;
sd.PgmInputs = NULL;
sd.TermQ = szQueueName;
sd.Environment = NULL;
sd.InheritOpt = SSF_INHERTOPT_PARENT;
sd.SessionType = SSF_TYPE_DEFAULT;
sd.IconFile = NULL;
sd.PgmHandle = 0;
sd.PgmControl = SSF_CONTROL_VISIBLE;
sd.InitXPos = 0;
sd.InitYPos = 0;
sd.InitXSize = 0;
sd.InitYSize = 0;
sd.Reserved = 0;
sd.ObjectBuffer = szObjBuffer;
sd.ObjectBuffLen = sizeof( szObjBuffer );
background = 0;
retcode = DosStartSession( &sd, &idSession, &pid );
if ( retcode == ERROR_SMG_START_IN_BACKGROUND ) {
background = 1;
retcode = 0;
}
if ( retcode ) {
printf( "launch of %s failed: %d %s\n", szPgm, retcode, szObjBuffer );
} else {
printf( "%s launched%s, session:%d pid:%d\n", szPgm,
background ? "(background)" : "", idSession, pid );
launched++;
}
}
while (launched--) {
retcode = DosReadQueue( hq, &Request,
&cbData,
&pbuf,
0,
DCWW_WAIT,
&priority,
NULLHANDLE );
if ( retcode ) {
printf( "DosReadQueue faild %d\n", retcode );
} else {
pSessionResult = (PSESSIONRESULT)pbuf;
printf( "pid:%d ulData:%d cbData:%d priority:%d ulSession:%d ulResult:%d\n",
Request.pid,
Request.ulData,
cbData,
(ULONG)priority,
pSessionResult->ulSessionID,
pSessionResult->ulResultCode );
retcode = DosFreeMem( pbuf );
if ( retcode ) {
printf( "Dosfreemem failed %d\n", retcode );
}
}
}
return( 0 );
}