home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / directx / duel / lobby.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-15  |  2.4 KB  |  131 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File:       lobby.c
  6.  *  Content:    DirectPlayLobby related code
  7.  *
  8.  *
  9.  ***************************************************************************/
  10. #include "lobby.h"
  11.  
  12. /*
  13.  * Externals
  14.  */
  15. extern LPDIRECTPLAY2                glpDP;                     // directplay object pointer
  16.  
  17. /*
  18.  * Globals
  19.  */
  20. LPDPLCONNECTION                        glpdplConnection;        // connection settings
  21.  
  22. /*
  23.  * Statics
  24.  */
  25. static LPDIRECTPLAYLOBBY            glpDPL;                    // lobby object pointer
  26.  
  27.  
  28.  
  29. /*
  30.  * DPLobbyCreate
  31.  *
  32.  * Wrapper for DirectPlayLobby DirectPlayLobbyCreate API.
  33.  */
  34. HRESULT DPLobbyCreate(void)
  35. {
  36.     HRESULT hr=E_FAIL;
  37.  
  38.     hr = DirectPlayLobbyCreate(NULL, &glpDPL, NULL, NULL, 0);    
  39.  
  40.     return hr;
  41. }
  42.  
  43. /*
  44.  * DPLobbyConnect
  45.  *
  46.  * Wrapper for DirectPlayLobby Connect API.
  47.  */
  48. HRESULT DPLobbyConnect(void)
  49. {
  50.     HRESULT hr=E_FAIL;
  51.  
  52.     hr = IDirectPlayLobby_Connect(glpDPL, 0, &glpDP, NULL) ;    
  53.  
  54.     return hr;
  55. }
  56.  
  57. /*
  58.  * DPLobbyGetConnectionSettings
  59.  *
  60.  * Wrapper for DirectPlayLobby GetConnectionSettings API
  61.  */
  62. HRESULT DPLobbyGetConnectionSettings(void)
  63. {
  64.     HRESULT hr=E_FAIL;
  65.     DWORD dwSize;
  66.  
  67.     if (glpDPL)
  68.     {
  69.         // get size for the connection settings structure
  70.         hr = IDirectPlayLobby_GetConnectionSettings(glpDPL, 0, NULL, &dwSize);
  71.         if (DPERR_BUFFERTOOSMALL == hr)
  72.         { 
  73.             // if we already have one, free it
  74.             if (glpdplConnection)
  75.             {
  76.                 free(glpdplConnection);
  77.                 glpdplConnection = NULL;
  78.             }
  79.  
  80.             // allocate memory for the new one
  81.             glpdplConnection = (LPDPLCONNECTION) malloc(dwSize);
  82.  
  83.             // get the connection settings
  84.             if (glpdplConnection)
  85.                 hr = IDirectPlayLobby_GetConnectionSettings(glpDPL, 0, glpdplConnection, &dwSize);
  86.         }
  87.     }
  88.  
  89.     return hr;
  90. }
  91.  
  92. /*
  93.  * DPLobbyRelease
  94.  *
  95.  * Wrapper for DirectPlayLobby Release API
  96.  */
  97. HRESULT DPLobbyRelease(void)
  98. {
  99.     HRESULT hr=E_FAIL;
  100.  
  101.     // free our connection settings
  102.     if (glpdplConnection)
  103.     {
  104.         free(glpdplConnection);
  105.         glpdplConnection = NULL;
  106.     }
  107.  
  108.     // release the lobby object
  109.     if (glpDPL)
  110.     {
  111.         hr = IDirectPlayLobby_Release(glpDPL);
  112.         glpDPL = NULL;
  113.     }
  114.     return hr;
  115. }
  116.  
  117. /*
  118.  * DPLobbySetConnectionSettings
  119.  *
  120.  * Wrapper for DirectPlayLobby SetConnectionSettings API
  121.  */
  122. HRESULT DPLobbySetConnectionSettings(void)
  123. {
  124.     HRESULT hr=E_FAIL;
  125.  
  126.     hr = IDirectPlayLobby_SetConnectionSettings(glpDPL, 0, 0, glpdplConnection);
  127.  
  128.     return hr;
  129. }
  130.  
  131.