home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / win32s / ut / samples / utsample / utsamp16.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  7.1 KB  |  172 lines

  1. /********************************************************************\
  2. *  Module: UTSamp16.c                                                *
  3. *                                                                    *
  4. *  Comments: Source for utsamp16.dll                                 *
  5. *                                                                    *                                                                    *
  6. *  Functions:                                                        *
  7. *                                                                    *
  8. *  LibMain()  - DLL entry point                                      *
  9. *  UTInit()   - Universal Thunk initialization procedure             *
  10. *  UTProc()   - Dispatch routine                                     *
  11. *  WEP()      - Windows exit procedure                               *
  12. *                                                                    *
  13. *                                                                    *
  14. \********************************************************************/
  15.  
  16. /*********************  Header Files  *********************/
  17.  
  18. #ifndef APIENTRY
  19. #define APIENTRY
  20. #endif
  21. #define W32SUT_16
  22.  
  23. #include <windows.h>
  24. #include "w32sut.h"
  25. #include "utsamp.h"
  26.  
  27. /*********************    Globals     *********************/
  28.  
  29. UT16CBPROC glpfnUT16CallBack;
  30.  
  31. /********************************************************************\
  32. * Function: LRESULT CALLBACK LibMain(HANDLE, WORD, WORD, LPSTR)      *
  33. *                                                                    *
  34. *  Purpose: DLL entry point                                          *
  35. *                                                                    *
  36. * Comments: No special processing required                           *
  37. *                                                                    *
  38. *                                                                    *
  39. \********************************************************************/
  40.  
  41. int FAR PASCAL LibMain( HANDLE hLibInst, WORD wDataSeg,
  42.             WORD cbHeapSize, LPSTR lpszCmdLine)
  43. {
  44.    return (1);
  45. } // LibMain()
  46.  
  47. /********************************************************************\
  48. * Function: DWORD FAR PASCAL UTInit(UT16CBPROC, LPVOID)              *
  49. *                                                                   f *
  50. *  Purpose: Universal Thunk initialization procedure                 *
  51. *                                                                    *
  52. * Comments: Store callback procedure address in global variable      *
  53. *                                                                    *
  54. *                                                                    *
  55. \********************************************************************/
  56.  
  57. DWORD FAR PASCAL UTInit( UT16CBPROC lpfnUT16CallBack, LPVOID lpBuf )
  58. {
  59.    glpfnUT16CallBack = lpfnUT16CallBack;
  60.    return(1);   // Return Success
  61. } // UTInit()
  62.  
  63.  
  64. /********************************************************************\
  65. * Function: DWORD FAR PASCAL UTProc(LPVOID, DWORD)                   *
  66. *                                                                    *
  67. *  Purpose: Dispatch routine called by 32-bit UT DLL                 *
  68. *                                                                    *
  69. * Comments: Call the appropriate Win16 API based on the dwFunc       *
  70. *           parameter. Extract any necessary parameters from the     *
  71. *           lpBuf buffer. This function must be exported.            *
  72. *                                                                    *
  73. *                                                                    *
  74. \********************************************************************/
  75.  
  76. DWORD FAR PASCAL UTProc( LPVOID lpBuf, DWORD dwFunc)
  77. {
  78.    switch (dwFunc)
  79.    {
  80.       case MYGETFREESPACE:
  81.          return( GetFreeSpace( (UINT) 0 ) );
  82.  
  83.       case MYWNETGETUSER:
  84.       {
  85.        // Windows for Workgroups supports multiple networks.
  86.        // to get WNetGetUser to function properly on that
  87.        // NOS, we must call MNetSetNextTarget passing the
  88.        // handle returned from MNetGetLastTarget
  89.  
  90.          static HANDLE hNetDrv;
  91.  
  92.          HINSTANCE hWfwNet = 0;
  93.          FARPROC   pMNetNetworkEnum   = NULL;
  94.          FARPROC   pMNetSetNextTarget = NULL;
  95.          WORD      wRetEnum;
  96.          DWORD     Temp;
  97.  
  98.          SetErrorMode( SEM_NOOPENFILEERRORBOX );
  99.  
  100.          hWfwNet = LoadLibrary( "WFWNET.DRV" );
  101.  
  102.          SetErrorMode( 0 );
  103.  
  104.          if( hWfwNet <= HINSTANCE_ERROR )
  105.          {  // Not WFW
  106.             hWfwNet = 0;
  107.             Temp = WNetGetUser( (LPSTR) ((LPDWORD)lpBuf)[0],
  108.                                 (LPWORD) ((LPDWORD)lpBuf)[1] );
  109.          }
  110.          else
  111.          {  // WFW running
  112.             pMNetNetworkEnum = GetProcAddress( hWfwNet, "MNetNetworkEnum" );
  113.             pMNetSetNextTarget = GetProcAddress( hWfwNet, "MNetSetNextTarget" );
  114.  
  115.             if( pMNetNetworkEnum && pMNetSetNextTarget )
  116.             {
  117.                hNetDrv = 0;
  118.                wRetEnum = (WORD) ((*pMNetNetworkEnum)((HANDLE FAR *)&hNetDrv));
  119.  
  120.                while( wRetEnum == WN_SUCCESS )
  121.                {
  122.                   (*pMNetSetNextTarget)( hNetDrv );   // activate network
  123.                   Temp = WNetGetUser( (LPSTR) ((LPDWORD)lpBuf)[0],
  124.                                       (LPWORD)((LPDWORD)lpBuf)[1] );
  125.  
  126.                   if( Temp == WN_SUCCESS )
  127.                      break;  // terminate on success or end of enumeration
  128.                   // otherwise try the next one for WNetGetUser support
  129.                   wRetEnum = (WORD) ((*pMNetNetworkEnum)((HANDLE FAR *) &hNetDrv));
  130.                }
  131.                if( Temp != WN_SUCCESS )
  132.                   *((LPSTR)((LPDWORD)lpBuf)[0]) = 0;
  133.             }
  134.             else // MNetXXX functions not found
  135.                Temp = WNetGetUser( (LPSTR) ((LPDWORD)lpBuf)[0],
  136.                                    (LPWORD) ((LPDWORD)lpBuf)[1] );
  137.          }
  138.  
  139.          if (hWfwNet)
  140.         FreeLibrary( hWfwNet );
  141.  
  142.          return( Temp );
  143.  
  144.       } // case MYWNETGETUSER:
  145.  
  146.       case MYCALLBACK1: // example calling back to a 32-bit function
  147.          (*glpfnUT16CallBack)( NULL, MYFUNC1, NULL );
  148.          break;
  149.  
  150.       case MYCALLBACK2: // example calling back to a 32-bit function
  151.          (*glpfnUT16CallBack)( NULL, MYFUNC2, NULL );
  152.          break;
  153.    } // switch (dwFunc)
  154.  
  155.    return( (DWORD)-1L ); // We should never get here.
  156. } // UTProc()
  157.  
  158. /********************************************************************\
  159. * Function: int FAR PASCAL WEP(int)                                  *
  160. *                                                                    *
  161. *  Purpose: Windows exit procedure                                   *
  162. *                                                                    *
  163. * Comments: No special processing required.                          *
  164. *                                                                    *
  165. *                                                                    *
  166. \********************************************************************/
  167.  
  168. int FAR PASCAL WEP( int bSystemExit )
  169. {
  170.    return (1);
  171. } // WEP()
  172.