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

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