Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
5.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dpsessdataobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dpSessDataObj.h"
  14. extern BSTR GUIDtoBSTR(LPGUID pg);
  15. extern HRESULT BSTRtoGUID(LPGUID pg,BSTR s);
  16. C_dxj_DirectPlaySessionDataObject::C_dxj_DirectPlaySessionDataObject()
  17. {
  18. ZeroMemory(&m_desc,sizeof(DPSESSIONDESC2));
  19. m_desc.dwSize=sizeof(DPSESSIONDESC2);
  20. }
  21. C_dxj_DirectPlaySessionDataObject::~C_dxj_DirectPlaySessionDataObject()
  22. {
  23. if (m_desc.lpszSessionName) SysFreeString((BSTR)m_desc.lpszSessionName);
  24. if (m_desc.lpszPassword) SysFreeString((BSTR)m_desc.lpszPassword);
  25. }
  26. HRESULT C_dxj_DirectPlaySessionDataObject::setGuidInstance( BSTR guid)
  27. {
  28. HRESULT hr =BSTRtoGUID(&m_desc.guidInstance,guid);
  29. return hr;
  30. }
  31. HRESULT C_dxj_DirectPlaySessionDataObject::getGuidInstance( BSTR *guid)
  32. {
  33. *guid=GUIDtoBSTR(&m_desc.guidInstance);
  34. return S_OK;
  35. }
  36. HRESULT C_dxj_DirectPlaySessionDataObject::setGuidApplication( BSTR guid)
  37. {
  38. HRESULT hr =BSTRtoGUID(&m_desc.guidApplication,guid);
  39. return hr;
  40. }
  41. HRESULT C_dxj_DirectPlaySessionDataObject::getGuidApplication( BSTR *guid)
  42. {
  43. *guid=GUIDtoBSTR(&m_desc.guidApplication);
  44. return S_OK;
  45. }
  46. HRESULT C_dxj_DirectPlaySessionDataObject::setMaxPlayers( long val)
  47. {
  48. m_desc.dwMaxPlayers=(DWORD)val;
  49. return S_OK;
  50. }
  51. HRESULT C_dxj_DirectPlaySessionDataObject::getMaxPlayers( long *val)
  52. {
  53. *val=(long)m_desc.dwMaxPlayers;
  54. return S_OK;
  55. }
  56. HRESULT C_dxj_DirectPlaySessionDataObject::setCurrentPlayers( long val)
  57. {
  58. m_desc.dwCurrentPlayers=(DWORD)val;
  59. return S_OK;
  60. }
  61. HRESULT C_dxj_DirectPlaySessionDataObject::getCurrentPlayers( long *val)
  62. {
  63. *val=(long)m_desc.dwCurrentPlayers;
  64. return S_OK;
  65. }
  66. HRESULT C_dxj_DirectPlaySessionDataObject::setSessionName( BSTR name)
  67. {
  68. if (m_desc.lpszSessionName) SysFreeString((BSTR)m_desc.lpszSessionName);
  69. m_desc.lpszSessionName=SysAllocString(name);
  70. return S_OK;
  71. }
  72. HRESULT C_dxj_DirectPlaySessionDataObject::getSessionName( BSTR *name)
  73. {
  74. *name=SysAllocString(m_desc.lpszSessionName);
  75. return S_OK;
  76. }
  77. HRESULT C_dxj_DirectPlaySessionDataObject::setSessionPassword( BSTR name)
  78. {
  79. if (m_desc.lpszPassword) SysFreeString((BSTR)m_desc.lpszPassword);
  80. m_desc.lpszPassword=SysAllocString(name);
  81. return S_OK;
  82. }
  83. HRESULT C_dxj_DirectPlaySessionDataObject::getSessionPassword( BSTR *name)
  84. {
  85. *name=SysAllocString(m_desc.lpszPassword);
  86. return S_OK;
  87. }
  88. HRESULT C_dxj_DirectPlaySessionDataObject::setFlags( long val)
  89. {
  90. m_desc.dwFlags=(DWORD)val;
  91. return S_OK;
  92. }
  93. HRESULT C_dxj_DirectPlaySessionDataObject::getFlags( long *val)
  94. {
  95. *val=(long)m_desc.dwFlags;
  96. return S_OK;
  97. }
  98. HRESULT C_dxj_DirectPlaySessionDataObject::setUser1( long val)
  99. {
  100. m_desc.dwUser1=(DWORD)val;
  101. return S_OK;
  102. }
  103. HRESULT C_dxj_DirectPlaySessionDataObject::getUser1( long *val)
  104. {
  105. *val=(long)m_desc.dwUser1;
  106. return S_OK;
  107. }
  108. HRESULT C_dxj_DirectPlaySessionDataObject::setUser2( long val)
  109. {
  110. m_desc.dwUser2=(DWORD)val;
  111. return S_OK;
  112. }
  113. HRESULT C_dxj_DirectPlaySessionDataObject::getUser2( long *val)
  114. {
  115. *val=(long)m_desc.dwUser2;
  116. return S_OK;
  117. }
  118. HRESULT C_dxj_DirectPlaySessionDataObject::setUser3( long val)
  119. {
  120. m_desc.dwUser3=(DWORD)val;
  121. return S_OK;
  122. }
  123. HRESULT C_dxj_DirectPlaySessionDataObject::getUser3( long *val)
  124. {
  125. *val=(long)m_desc.dwUser3;
  126. return S_OK;
  127. }
  128. HRESULT C_dxj_DirectPlaySessionDataObject::setUser4( long val)
  129. {
  130. m_desc.dwUser4=(DWORD)val;
  131. return S_OK;
  132. }
  133. HRESULT C_dxj_DirectPlaySessionDataObject::getUser4( long *val)
  134. {
  135. *val=(long)m_desc.dwUser4;
  136. return S_OK;
  137. }
  138. void C_dxj_DirectPlaySessionDataObject::init(DPSESSIONDESC2 *desc)
  139. {
  140. memcpy(&m_desc,desc,sizeof(DPSESSIONDESC2));
  141. m_desc.lpszSessionName=SysAllocString(desc->lpszSessionName);
  142. m_desc.lpszPassword=SysAllocString(desc->lpszPassword);
  143. }
  144. void C_dxj_DirectPlaySessionDataObject::init(DPSessionDesc2 *desc)
  145. {
  146. m_desc.lpszSessionName=SysAllocString(desc->strSessionName);
  147. m_desc.lpszPassword=SysAllocString(desc->strPassword);
  148. BSTRtoGUID(&(m_desc.guidInstance),desc->strGuidInstance);
  149. BSTRtoGUID(&(m_desc.guidApplication),desc->strGuidApplication);
  150. m_desc.lpszPassword=SysAllocString(desc->strPassword);
  151. m_desc.dwSize=sizeof(DPSESSIONDESC2);
  152. m_desc.dwFlags=desc->lFlags;
  153. m_desc.dwMaxPlayers=desc->lMaxPlayers;
  154. m_desc.dwCurrentPlayers=desc->lCurrentPlayers;
  155. m_desc.dwUser1=desc->lUser1;
  156. m_desc.dwUser2=desc->lUser2;
  157. m_desc.dwUser3=desc->lUser3;
  158. m_desc.dwUser4=desc->lUser4;
  159. }
  160. HRESULT C_dxj_DirectPlaySessionDataObject::create(DPSESSIONDESC2 *desc,I_dxj_DirectPlaySessionData **ret)
  161. {
  162. HRESULT hr;
  163. if (!ret) return E_INVALIDARG;
  164. C_dxj_DirectPlaySessionDataObject *c=NULL;
  165. c=new CComObject<C_dxj_DirectPlaySessionDataObject>;
  166. if( c == NULL ) return E_OUTOFMEMORY;
  167. if (desc) c->init(desc);
  168. hr=c->QueryInterface(IID_I_dxj_DirectPlaySessionData, (void**)ret);
  169. return hr;
  170. }
  171. HRESULT C_dxj_DirectPlaySessionDataObject::create(DPSessionDesc2 *desc,I_dxj_DirectPlaySessionData **ret)
  172. {
  173. HRESULT hr;
  174. if (!ret) return E_INVALIDARG;
  175. C_dxj_DirectPlaySessionDataObject *c=NULL;
  176. c=new CComObject<C_dxj_DirectPlaySessionDataObject>;
  177. if( c == NULL ) return E_OUTOFMEMORY;
  178. if (desc) c->init(desc);
  179. hr=c->QueryInterface(IID_I_dxj_DirectPlaySessionData, (void**)ret);
  180. return hr;
  181. }
  182. HRESULT C_dxj_DirectPlaySessionDataObject::getData(void *val){
  183. __try {
  184. memcpy(val,&m_desc,sizeof(DPSESSIONDESC2));
  185. }
  186. __except(1,1){
  187. return E_FAIL;
  188. }
  189. return S_OK;
  190. }