home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / iwftech.zip / samples / Launch / wklaunch.c < prev    next >
Text File  |  1994-07-28  |  6KB  |  121 lines

  1. /*+--------------------------------------------------------------------------+*/
  2. /*|WF/2 Launching actions sample                                             |*/
  3. /*|--------------------------------------------------------------------------|*/
  4. /*|                                                                          |*/
  5. /*| PROGRAM NAME: LAUNCH                                                     |*/
  6. /*| -------------                                                            |*/
  7. /*|                                                                          |*/
  8. /*| COPYRIGHT:                                                               |*/
  9. /*| ----------                                                               |*/
  10. /*| Copyright (C) International Business Machines Corp., 1991,1992,1993,1994.|*/
  11. /*|                                                                          |*/
  12. /*| DISCLAIMER OF WARRANTIES:                                                |*/
  13. /*| -------------------------                                                |*/
  14. /*| The following [enclosed] code is sample code created by IBM              |*/
  15. /*| Corporation.  This sample code is not part of any standard IBM product   |*/
  16. /*| and is provided to you solely for the purpose of assisting you in the    |*/
  17. /*| development of your applications.  The code is provided "AS IS",         |*/
  18. /*| without warranty of any kind.  IBM shall not be liable for any damages   |*/
  19. /*| arising out of your use of the sample code, even if they have been       |*/
  20. /*| advised of the possibility of such damages.                              |*/
  21. /*|                                                                          |*/
  22. /*| REVISION LEVEL: 2.1                                                      |*/
  23. /*| -------------------                                                      |*/
  24. /*|                                                                          |*/
  25. /*|  This program illustrates registering a non-PM program with WF/2 and     |*/
  26. /*|  launching context sensitive actions. Also, this program does not        |*/
  27. /*|  statically link to WF/2, and can be used where WF/2 support is optional.|*/
  28. /*|                                                                          |*/
  29. /*+--------------------------------------------------------------------------+*/
  30. #define INCL_ERRORS
  31. #define INCL_DOS
  32. #define INCL_WIN
  33. #include <os2.h>
  34.  
  35. #define INCL_WKFMSG
  36. #include <wkf.h>
  37.  
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <ctype.h>
  42.  
  43. BOOL _System WkfLaunchAction( PSZ   pszProject,
  44.                               PSZ   pszAction,
  45.                               PSZ * ppszFiles )
  46.    {
  47.    HMODULE          hMod;
  48.    LHANDLE          hRouter;
  49.  
  50.    PWKF_EXECUTEINFO pExecuteInfo;
  51.    ULONG            ulSizeofBuffer;
  52.    ULONG            i;
  53.    PSZ              pszCurr;
  54.    ULONG            ulNameLen;
  55.    BOOL             bReturn = FALSE;
  56.  
  57.  
  58.       /* ---------------------------------------------------------------- */
  59.       /* register ourselves with the router                               */
  60.       /* ---------------------------------------------------------------- */
  61.       hRouter = WkfInitialize ( WKF_CONNECT_PIPE,
  62.                                 NULLHANDLE, /* we don't care about 2 way comm */
  63.                                 WKF_TYPE_FILETOOL,
  64.                                 "FileTool",
  65.                                 0,
  66.                                 WKF_OPT_NONE );
  67.       if ( hRouter == NULLHANDLE )
  68.          return( FALSE );
  69.  
  70.       ulSizeofBuffer = sizeof( WKF_EXECUTEINFO );
  71.       i = 0;
  72.       while( ppszFiles[i] ) i++;
  73.  
  74.       ulSizeofBuffer = sizeof( WKF_EXECUTEINFO ) + i*CCHMAXPATH;
  75.  
  76.       /* ---------------------------------------------------------------- */
  77.       /* build up the execute editor message                              */
  78.       /* ---------------------------------------------------------------- */
  79.       pExecuteInfo            = calloc( 1, ulSizeofBuffer );
  80.       if ( pExecuteInfo==NULL )
  81.          return( FALSE );
  82.  
  83.       pExecuteInfo->cb        = ulSizeofBuffer;
  84.       pExecuteInfo->hActionId = NULLHANDLE;
  85.       /* pExecuteInfo->flOptions = WKF_MTR_MINIMIZE | WKF_MTR_AUTOCLOSE; */
  86.       pExecuteInfo->flOptions = 0;
  87.       pExecuteInfo->ulRunMode = 0;
  88.       strcpy( pExecuteInfo->szProjectFile, pszProject );
  89.       strcpy( pExecuteInfo->szActionName, "" );
  90.       strcpy( pExecuteInfo->szActionClass, pszAction );
  91.       pExecuteInfo->cFiles = i;
  92.       i = 0;
  93.       pszCurr = pExecuteInfo->szFiles;
  94.       /* ---------------------------------------------------------------- */
  95.       /* build up the files list                                          */
  96.       /* ---------------------------------------------------------------- */
  97.       while( ppszFiles[i] )
  98.          {
  99.          ulNameLen = strlen( ppszFiles[i] );
  100.          memcpy( pszCurr, ppszFiles[i], ulNameLen );
  101.          pszCurr[ulNameLen] = WKF_LIST_DELIM;
  102.          pszCurr += ulNameLen + 1;
  103.          i++;
  104.          }
  105.  
  106.       /* ---------------------------------------------------------------- */
  107.       /* send out the request message                                     */
  108.       /* ---------------------------------------------------------------- */
  109.       bReturn =
  110.         WkfNotify (hRouter, NULLHANDLE, WKFM_EXECUTEACTION, pExecuteInfo);
  111.  
  112.       /* ---------------------------------------------------------------- */
  113.       /* deregister with the wormhole                                     */
  114.       /* ---------------------------------------------------------------- */
  115.       WkfTerminate (hRouter, NULLHANDLE);
  116.  
  117.       free( pExecuteInfo );
  118.  
  119.       return( bReturn );
  120.    }
  121.