home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / strout / remote.c < prev    next >
C/C++ Source or Header  |  1996-07-23  |  4KB  |  93 lines

  1. /*************************************************************************
  2.                     Copyright Microsoft Corp. 1992-1996
  3.                         Remote Machine strout sample
  4.  
  5.   FILE      :   remote.c
  6.  
  7.   PURPOSE   :   The remote procedures that will be called from the client.
  8.  
  9.   COMMENTS  :   These procedures will be linked into the server side of 
  10.                 the application.
  11.  
  12. *************************************************************************/
  13. #include "strout.h"                 //Generated by the MIDL compiler   
  14. #include "common.h"                 //Common definitions for all files 
  15.  
  16. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  17. /*  Procedure   :   void GetRemoteEnv(unsigned long, str **)            */
  18. /*  Desc.       :   This procedure get the environment variables from   */
  19. /*                  the server and reuturns a pointer to an array of    */
  20. /*                  pointer to the environment strings                  */
  21. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  22. void GetRemoteEnv(unsigned long *nNumLines, str **psEnvironmentBlock)
  23. {
  24.     int nIdx = 0;       // Loop counter                                 
  25.     TCHAR 
  26.         *pcTemp,        // Temporary pointer to the environment block   
  27.         *pcEnv;         // Pointer to the environment block             
  28.  
  29.  
  30.     // Get pointer to environment block    
  31.     pcEnv = (TCHAR *) GetEnvironmentStrings();
  32.  
  33.     // First count how many lines, must know how much memory to allocate
  34.     *nNumLines  = 0;            // Initialize number of lines to 0      
  35.     pcTemp = pcEnv;             // Set tempptr equal to envptr          
  36.     while (*pcTemp != NULL_CHAR)
  37.     {
  38.         // Don't count the lines that starts with IGNORE_CHAR            
  39.         if(*pcTemp != IGNORE_CHAR)
  40.         {
  41.             (*nNumLines)++;     // Increase the number of lines     
  42.         }
  43.  
  44.         // Increment the string pointer. Each line ends in \0, and  
  45.         // \0\0 means end of block                                  
  46.         pcTemp += (_tcslen(pcTemp) + 1);
  47.     }
  48.  
  49.     // Allocate the memory needed for the line pointer 
  50.     if(NULL == (*psEnvironmentBlock = (str *) 
  51.         midl_user_allocate((*nNumLines) * sizeof(str))))
  52.     {
  53.         _tprintf(TEXT("REMOTE.C : Memory allocation error\n"));
  54.         return;
  55.     }
  56.  
  57.     // Iterate through all the environment strings, allocate memory,    
  58.     // and copy them                                                    
  59.     while (*pcEnv != NULL_CHAR)
  60.     {
  61.         // Don't count the lines that starts with IGNORE_CHAR
  62.         if(*pcEnv != IGNORE_CHAR)
  63.         {
  64.             // Allocate the space needed for the strings 
  65.             (*psEnvironmentBlock)[nIdx] = (str) midl_user_allocate(
  66.                 sizeof(TCHAR) * (_tcslen(pcEnv) + 1));
  67.             
  68.             // Copy the environment string to the allocated memory
  69.             _tcscpy((*psEnvironmentBlock)[nIdx++], pcEnv);
  70.         }
  71.         
  72.         // Increment the string pointer. Each line ends in \0, and
  73.         // \0\0 means end of block
  74.         pcEnv += (_tcslen(pcEnv) + 1);
  75.     }
  76. }
  77.  
  78.  
  79. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  80. /* Procedure    :   void ShutDown(void);                                */
  81. /* Desc.        :   This procedure send a message to the server that it */
  82. /*                  can    stop listening for remote procedure calls       */
  83. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  84. void ShutDown(void)
  85. {
  86.     RPC_STATUS nStatus;
  87.  
  88.     // Tell the server to stop listening for remote procedure calls
  89.     _tprintf(TEXT("Shutting down the server\n"));
  90.     nStatus = RpcMgmtStopServerListening(NULL);
  91.     EXIT_IF_FAIL(nStatus, "RpcMgmtStopServerListening");
  92. }
  93.