SU.OS2.FAQ--------------- < Пред. | След. > -- < @ > -- < Сообщ. > -- < Эхи > --
 Nп/п : 93 из 100
 От   : FAQServer                           2:5020/181        10 сен 24 07:37:04
 К    : All                                                   10 сен 24 07:47:02
 Тема : PRG25 - wait/cwait не yмеет pаботать с сессиями
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 2:5020/181 b3d72027
@RFC-Message-ID: 1@mhm.com.lan>
@TZUTC: 0300
[Q]: wait/cwait не yмеет pаботать с сессиями

[A]: Unknown author

 This small program will start any program synchronously using
 DosStartSession(). The important thing is the queue. When you specify
 SSF_RELATED_CHILD and a TermQ name, OS/2 will write the return code to the
 specified queue when the session terminates. I use this in an event
 scheduler by creating a separate thread that does reads from the queue but
 you can just as easily block on the main thread to catch the return code.
 That will, in effect, provide for synchronous execution. Note that one
 problem with SSF_RELATED_CHILD is that if the program that started the
 child dies, so does the child.

  #define  INCL_DOSERRORS
  #define  INCL_DOSPROCESS
  #define  INCL_DOSQUEUES
  #define  INCL_DOSSESMGR
  #include 
  #include 
  #include 
  #include 

  #define QUEUE_NAME    "\\QUEUES\\STRTSYNC.QUE"

  int main( int argc, char *argv[] );

  int main( int argc, char *argv[] )
  {
      APIRET rc;
      HQUEUE hque;

      if( argc < 2 )
          return 1;

      rc = DosCreateQueue( &hque, QUE_FIFO | QUE_CONVERT_ADDRESS, QUEUE_NAME );
      if( !rc )
      {
          STARTDATA   stdata;
          PID         pidSession;
          CHAR        szObjFail[ 50 ];
          ULONG       ulLength, idSession;
          REQUESTDATA rd;
          PUSHORT     pusInfo = NULL;
          BYTE        bPriority;

          (void) memset( &stdata, 0, sizeof( stdata ) );

          stdata.Length       = sizeof( STARTDATA );
          stdata.FgBg         = SSF_FGBG_FORE;
          stdata.TraceOpt     = SSF_TRACEOPT_NONE;
          stdata.PgmTitle     = "Rick`s Program";
          stdata.InheritOpt   = SSF_INHERTOPT_SHELL;
          stdata.SessionType  = SSF_TYPE_DEFAULT;
          stdata.PgmControl   = SSF_CONTROL_VISIBLE;
          stdata.ObjectBuffer = szObjFail;
          stdata.ObjectBuffLen= sizeof( szObjFail );
          stdata.Related      = SSF_RELATED_CHILD;
          stdata.TermQ        = QUEUE_NAME;
          stdata.PgmName      = argv[ 1 ];

          rc = DosStartSession( &stdata, &idSession, &pidSession );

          if( rc && rc != ERROR_SMG_START_IN_BACKGROUND )
          {
              printf( "DosStartSession RC(%u)
", rc );
              return (INT) rc;
          }

          rc = DosReadQueue( hque, &rd, &ulLength, (PPVOID) &pusInfo, 0,
                             DCWW_WAIT, &bPriority, 0 );

          if( rc && rc != ERROR_QUE_EMPTY )
          {
              printf( "DosReadQueue RC(%u)
", rc );
              return (INT) rc;
          }

          printf( "RetCode from Session %u: %u
",
                   pusInfo[ 0 ], pusInfo[ 1 ]);

          DosCloseQueue( hque );
      }
      else
      {
          printf( "DosCreateQueue RC(%u)
", rc );
          return (INT) rc;
      }

      return 0;
  }
 
--- INN 2.7.2
 * Origin: This echo is READ-ONLY. Send %HELP to FAQSERVER at (2:5020/181)
SEEN-BY: 4500/1 5001/100 5019/40 5020/77 81 181
545 848 1042 1941 1955 4441
SEEN-BY: 5020/8086 12000 5030/1081 1900 5060/900
5097/31 6090/1
@PATH: 5020/181 12000 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх