home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / samples / sample12 / sample12.cpp < prev    next >
C/C++ Source or Header  |  1997-04-03  |  2KB  |  86 lines

  1. #include "xheaders.h"
  2. #include XString_i
  3. #include XRexxInterface_i
  4. #include <stdio.h>
  5.  
  6. //this is the function which can be called from a rexx-script
  7. REXXINTERFACE MyFunc( PUCHAR name, ULONG argc, PRXSTRING argv, PSZ queue, PRXSTRING ret)
  8. {   
  9.    //any arguments?
  10.     if(argc > 0)
  11.     {
  12.         XString argument;
  13.         //yep, print them
  14.         for(int i = 0; i < argc;i++)
  15.         {
  16.              RXStringToXString( argv[i], argument);
  17.             printf("MyFunc (C++), arguments[%i]: %s\n", i, (char*) argument);
  18.         }
  19.     }
  20.     else
  21.        printf("MyFunc (C++): no args\n");
  22.  
  23.     //return a string-value, it will be posted to our rexx-handler
  24.     XString result = "NextCommand";
  25.     XStringToPRXString( result, ret);
  26.     return 0;
  27. }
  28.  
  29.  
  30. //a command-handler which will get commands from the rexx-script
  31. REXXINTERFACE Handler(PRXSTRING commandString, PUSHORT flags, PRXSTRING returnString)
  32. {
  33.    XString command;
  34.  
  35.     //convert 
  36.     PRXStringToXString(commandString, command);
  37.  
  38.    //no commands, return
  39.    if( command.IsEmpty())
  40.       return 0;
  41.  
  42.     //which command?    
  43.     if(command == "INIT_VARS")
  44.     {
  45.         //gt a pointer to the used rexx-interface
  46.         XRexxInterface * handler = XRexxInterface::GetHandler("Handler");
  47.         if(handler == NULL)
  48.         {
  49.             printf("no handler found");
  50.             return 0;
  51.         }
  52.         //set a varibale which can be used in the rexx-script
  53.         handler->SetVar( "TEST_VAR", "1.0");
  54.         printf( "Handler (C++): vars set\n");
  55.     }
  56.     else
  57.        printf( "Handler (C++): don∩t know how to handle command:%s\n", (char*) command);
  58.         
  59.     //end
  60.     *flags = RXSUBCOM_OK;
  61.     return 0;
  62. }
  63.  
  64.  
  65. int main(int argc, void ** argv)
  66. {
  67.     XString returnString, arg= "123";
  68.     SHORT returnValue;
  69.  
  70.     //register the function 'MyFunc' so it can be used from the rexx-script
  71.     if( XRexxInterface::RegisterFunction( "MyFunc", (PFN) MyFunc) !=0 )
  72.            printf( "cannot register function\n");
  73.  
  74.     //install a command-handler which will receive commands from the rexx-script
  75.     XRexxInterface handler( "Handler", (PFN) Handler);
  76.  
  77.     //run the rexx-script
  78.     LONG rc = handler.Execute( "test.mac", RXCOMMAND, &returnString, &returnValue, &arg );
  79.     if(rc)
  80.        printf("%i\n", rc);
  81.  
  82.     //end
  83.     printf("done, returned: %s\n", (char*) returnString);
  84.     return 0;
  85. }
  86.