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.

435 lines
9.7 KiB

  1. #include "stdafx.h"
  2. #include "Direct.h"
  3. #include "dms.h"
  4. #include "DPlayAddressObj.h"
  5. extern void *g_dxj_DirectPlayAddress;
  6. extern BSTR GUIDtoBSTR(LPGUID);
  7. extern HRESULT DPLAYBSTRtoGUID(LPGUID,BSTR);
  8. extern BOOL IsEmptyString(BSTR szString);
  9. #define SAFE_DELETE(p) { if(p) { delete (p); p=NULL; } }
  10. #define SAFE_RELEASE(p) { __try { if(p) { int i = 0; i = (p)->Release(); DPF1(1,"--DirectPlayAddress SafeRelease (RefCount = %d)\n",i); if (!i) { (p)=NULL;}} } __except(EXCEPTION_EXECUTE_HANDLER) { (p) = NULL;} }
  11. ///////////////////////////////////////////////////////////////////
  12. // InternalAddRef
  13. ///////////////////////////////////////////////////////////////////
  14. DWORD C_dxj_DirectPlayAddressObject::InternalAddRef(){
  15. DWORD i;
  16. i=CComObjectRoot::InternalAddRef();
  17. DPF2(1,"------ DXVB: DirectPlayAddress8 [%d] AddRef %d \n",creationid,i);
  18. return i;
  19. }
  20. ///////////////////////////////////////////////////////////////////
  21. // InternalRelease
  22. ///////////////////////////////////////////////////////////////////
  23. DWORD C_dxj_DirectPlayAddressObject::InternalRelease(){
  24. DWORD i;
  25. i=CComObjectRoot::InternalRelease();
  26. DPF2(1,"------ DXVB: DirectPlayAddress8 [%d] Release %d \n",creationid,i);
  27. return i;
  28. }
  29. ///////////////////////////////////////////////////////////////////
  30. // C_dxj_DirectPlayAddressObject
  31. ///////////////////////////////////////////////////////////////////
  32. C_dxj_DirectPlayAddressObject::C_dxj_DirectPlayAddressObject(){
  33. DPF1(1,"------ DXVB: Constructor Creation DirectPlayAddress8 Object[%d] \n ",g_creationcount);
  34. m__dxj_DirectPlayAddress = NULL;
  35. m_pUserData = NULL;
  36. m_dwUserDataSize = 0;
  37. g_dxj_DirectPlayAddress = (void *)this;
  38. }
  39. ///////////////////////////////////////////////////////////////////
  40. // ~C_dxj_DirectPlayAddressObject
  41. ///////////////////////////////////////////////////////////////////
  42. C_dxj_DirectPlayAddressObject::~C_dxj_DirectPlayAddressObject()
  43. {
  44. DPF(1,"Entering ~C_dxj_DirectPlayAddressObject destructor \n");
  45. __try {
  46. SAFE_RELEASE(m__dxj_DirectPlayAddress);
  47. }
  48. __except(EXCEPTION_EXECUTE_HANDLER)
  49. {
  50. m__dxj_DirectPlayAddress = NULL;
  51. }
  52. SAFE_DELETE(m_pUserData);
  53. }
  54. HRESULT C_dxj_DirectPlayAddressObject::InternalGetObject(IUnknown **pUnk){
  55. *pUnk=(IUnknown*)m__dxj_DirectPlayAddress;
  56. return S_OK;
  57. }
  58. HRESULT C_dxj_DirectPlayAddressObject::InternalSetObject(IUnknown *pUnk){
  59. m__dxj_DirectPlayAddress=(IDirectPlay8Address*)pUnk;
  60. return S_OK;
  61. }
  62. HRESULT C_dxj_DirectPlayAddressObject::BuildFromURL(BSTR SourceURL)
  63. {
  64. HRESULT hr;
  65. __try {
  66. if (FAILED(hr = m__dxj_DirectPlayAddress->BuildFromURLW(SourceURL) ) )
  67. return hr;
  68. }
  69. __except(EXCEPTION_EXECUTE_HANDLER)
  70. {
  71. return E_FAIL;
  72. }
  73. return S_OK;
  74. }
  75. HRESULT C_dxj_DirectPlayAddressObject::Duplicate(I_dxj_DirectPlayAddress **NewAddress)
  76. {
  77. HRESULT hr;
  78. IDirectPlay8Address *lpDup = NULL;
  79. __try {
  80. if (FAILED (hr = m__dxj_DirectPlayAddress->Duplicate(&lpDup) ) )
  81. return hr;
  82. INTERNAL_CREATE_ADDRESS(_dxj_DirectPlayAddress, lpDup, NewAddress);
  83. }
  84. __except(EXCEPTION_EXECUTE_HANDLER)
  85. {
  86. return E_FAIL;
  87. }
  88. return S_OK;
  89. }
  90. HRESULT C_dxj_DirectPlayAddressObject::Clear()
  91. {
  92. HRESULT hr;
  93. __try {
  94. if (FAILED ( hr = m__dxj_DirectPlayAddress->Clear() ) )
  95. return hr;
  96. }
  97. __except(EXCEPTION_EXECUTE_HANDLER)
  98. {
  99. return E_FAIL;
  100. }
  101. return S_OK;
  102. }
  103. HRESULT C_dxj_DirectPlayAddressObject::GetURL(BSTR *URL)
  104. {
  105. HRESULT hr;
  106. WCHAR wszUrl[MAX_PATH];
  107. DWORD dwNumChars = 0;
  108. __try {
  109. hr = m__dxj_DirectPlayAddress->GetURLW(NULL, &dwNumChars);
  110. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  111. return hr;
  112. if (FAILED (hr = m__dxj_DirectPlayAddress->GetURLW(&wszUrl[0],&dwNumChars) ) )
  113. return hr;
  114. *URL = SysAllocString(&wszUrl[0]);
  115. }
  116. __except(EXCEPTION_EXECUTE_HANDLER)
  117. {
  118. return E_FAIL;
  119. }
  120. return S_OK;
  121. }
  122. HRESULT C_dxj_DirectPlayAddressObject::GetSP(BSTR *guidSP)
  123. {
  124. HRESULT hr;
  125. GUID guidDev;
  126. __try {
  127. if (FAILED (hr = m__dxj_DirectPlayAddress->GetSP(&guidDev ) ) )
  128. return hr;
  129. GUID* pGuid = new GUID;
  130. if (!pGuid)
  131. return E_OUTOFMEMORY;
  132. memcpy( pGuid, &guidDev, sizeof(GUID) );
  133. *guidSP = GUIDtoBSTR(pGuid);
  134. SAFE_DELETE(pGuid);
  135. }
  136. __except(EXCEPTION_EXECUTE_HANDLER)
  137. {
  138. return E_FAIL;
  139. }
  140. return S_OK;
  141. }
  142. HRESULT C_dxj_DirectPlayAddressObject::GetUserData(void *UserData, long *lBufferSize)
  143. {
  144. __try {
  145. DPF(1,"-----Entering (DplayAddress) GetUserData call...\n");
  146. //Copy the memory over to our new variable
  147. memcpy(UserData,m_pUserData,m_dwUserDataSize);
  148. lBufferSize = (long*)&m_dwUserDataSize;
  149. }
  150. __except(EXCEPTION_EXECUTE_HANDLER)
  151. {
  152. return E_FAIL;
  153. }
  154. return S_OK;
  155. }
  156. HRESULT C_dxj_DirectPlayAddressObject::SetSP(BSTR guidSP)
  157. {
  158. HRESULT hr;
  159. GUID guidDev;
  160. __try {
  161. if (guidSP)
  162. {
  163. if (FAILED( hr = DPLAYBSTRtoGUID(&guidDev, guidSP) ) )
  164. return hr;
  165. }
  166. else
  167. return E_INVALIDARG;
  168. if (FAILED ( hr = m__dxj_DirectPlayAddress->SetSP(&guidDev) ))
  169. return hr;
  170. }
  171. __except(EXCEPTION_EXECUTE_HANDLER)
  172. {
  173. return E_FAIL;
  174. }
  175. return S_OK;
  176. }
  177. HRESULT C_dxj_DirectPlayAddressObject::SetUserData(void *UserData, long lDataSize)
  178. {
  179. __try {
  180. DPF(1,"-----Entering (DplayAddress) SetUserData call...\n");
  181. if (m_pUserData)
  182. SAFE_DELETE(m_pUserData);
  183. m_pUserData = (void*)new BYTE[lDataSize];
  184. if (!m_pUserData)
  185. return E_OUTOFMEMORY;
  186. memcpy((void*) m_pUserData, (void*)UserData, lDataSize);
  187. m_dwUserDataSize = (DWORD)lDataSize;
  188. }
  189. __except(EXCEPTION_EXECUTE_HANDLER)
  190. {
  191. return E_FAIL;
  192. }
  193. return S_OK;
  194. }
  195. HRESULT C_dxj_DirectPlayAddressObject::GetNumComponents(long *lNumComponents)
  196. {
  197. HRESULT hr;
  198. __try {
  199. if (FAILED (hr = m__dxj_DirectPlayAddress->GetNumComponents((DWORD*) lNumComponents) ) )
  200. return hr;
  201. }
  202. __except(EXCEPTION_EXECUTE_HANDLER)
  203. {
  204. return E_FAIL;
  205. }
  206. return S_OK;
  207. }
  208. HRESULT C_dxj_DirectPlayAddressObject::GetDevice(BSTR *guidDevice)
  209. {
  210. HRESULT hr;
  211. GUID guidDev;
  212. __try {
  213. if (FAILED (hr = m__dxj_DirectPlayAddress->GetDevice(&guidDev ) ) )
  214. return hr;
  215. GUID* pGuid = new GUID;
  216. if (!pGuid)
  217. return E_OUTOFMEMORY;
  218. memcpy( pGuid, &guidDev, sizeof(GUID) );
  219. *guidDevice = GUIDtoBSTR(pGuid);
  220. SAFE_DELETE(pGuid);
  221. }
  222. __except(EXCEPTION_EXECUTE_HANDLER)
  223. {
  224. return E_FAIL;
  225. }
  226. return S_OK;
  227. }
  228. HRESULT C_dxj_DirectPlayAddressObject::SetDevice(BSTR guidDevice)
  229. {
  230. HRESULT hr;
  231. GUID guidDev;
  232. __try {
  233. if (guidDevice)
  234. {
  235. if (FAILED( hr = DPLAYBSTRtoGUID(&guidDev, guidDevice) ) )
  236. return hr;
  237. }
  238. else
  239. return E_INVALIDARG;
  240. if (FAILED ( hr = m__dxj_DirectPlayAddress->SetDevice(&guidDev) ))
  241. return hr;
  242. }
  243. __except(EXCEPTION_EXECUTE_HANDLER)
  244. {
  245. return E_FAIL;
  246. }
  247. return S_OK;
  248. }
  249. HRESULT C_dxj_DirectPlayAddressObject::SetEqual(I_dxj_DirectPlayAddress *Address)
  250. {
  251. HRESULT hr;
  252. __try {
  253. DO_GETOBJECT_NOTNULL( IDirectPlay8Address*, lpAddress, Address);
  254. if (FAILED (hr = m__dxj_DirectPlayAddress->SetEqual( lpAddress) ))
  255. return hr;
  256. }
  257. __except(EXCEPTION_EXECUTE_HANDLER)
  258. {
  259. return E_FAIL;
  260. }
  261. return S_OK;
  262. }
  263. HRESULT C_dxj_DirectPlayAddressObject::AddComponentLong(BSTR sComponent, long lValue)
  264. {
  265. HRESULT hr;
  266. WCHAR wszComponent[MAX_PATH];
  267. __try {
  268. if (!IsEmptyString(sComponent)) wcscpy(wszComponent, sComponent);
  269. if (FAILED (hr = m__dxj_DirectPlayAddress->AddComponent(wszComponent, (DWORD*) &lValue, sizeof(DWORD), DPNA_DATATYPE_DWORD ) ) )
  270. return hr;
  271. }
  272. __except(EXCEPTION_EXECUTE_HANDLER)
  273. {
  274. return E_FAIL;
  275. }
  276. return S_OK;
  277. }
  278. HRESULT C_dxj_DirectPlayAddressObject::AddComponentString(BSTR sComponent, BSTR sValue)
  279. {
  280. HRESULT hr;
  281. WCHAR wszComponent[MAX_PATH];
  282. WCHAR wszValue[MAX_PATH];
  283. __try {
  284. if (!IsEmptyString(sComponent)) wcscpy(wszComponent, sComponent);
  285. if (!IsEmptyString(sValue)) wcscpy(wszValue, sValue);
  286. if (FAILED (hr = m__dxj_DirectPlayAddress->AddComponent(wszComponent, (WCHAR*) &wszValue, (((DWORD*)sValue)[-1]) + sizeof(WCHAR), DPNA_DATATYPE_STRING ) ) )
  287. return hr;
  288. }
  289. __except(EXCEPTION_EXECUTE_HANDLER)
  290. {
  291. return E_FAIL;
  292. }
  293. return S_OK;
  294. }
  295. HRESULT C_dxj_DirectPlayAddressObject::GetComponentLong(BSTR sComponent, long *lValue)
  296. {
  297. HRESULT hr;
  298. WCHAR wszComponent[MAX_PATH];
  299. DWORD dwSize = 0;
  300. DWORD dwDataType = DPNA_DATATYPE_DWORD;
  301. DWORD dwData = 0;
  302. __try {
  303. if (!IsEmptyString(sComponent))
  304. {
  305. wcscpy(wszComponent, sComponent);
  306. }
  307. else
  308. return E_INVALIDARG;
  309. hr = m__dxj_DirectPlayAddress->GetComponentByName(wszComponent, NULL, &dwSize, &dwDataType);
  310. if (FAILED(hr) && (hr != DPNERR_BUFFERTOOSMALL))
  311. return hr;
  312. if (FAILED (hr = m__dxj_DirectPlayAddress->GetComponentByName(wszComponent, &dwData, &dwSize, &dwDataType) ) )
  313. return hr;
  314. *lValue = dwData;
  315. }
  316. __except(EXCEPTION_EXECUTE_HANDLER)
  317. {
  318. return E_FAIL;
  319. }
  320. return S_OK;
  321. }
  322. HRESULT C_dxj_DirectPlayAddressObject::GetComponentString(BSTR sComponent, BSTR *sValue)
  323. {
  324. HRESULT hr;
  325. WCHAR wszComponent[MAX_PATH];
  326. DWORD dwSize = 0;
  327. DWORD dwDataType = DPNA_DATATYPE_STRING;
  328. WCHAR *wszRet = NULL;
  329. __try {
  330. if (!IsEmptyString(sComponent))
  331. {
  332. wcscpy(wszComponent, sComponent);
  333. }
  334. else
  335. return E_INVALIDARG;
  336. hr = m__dxj_DirectPlayAddress->GetComponentByName(wszComponent, NULL, &dwSize, &dwDataType);
  337. if (FAILED(hr) && (hr != DPNERR_BUFFERTOOSMALL))
  338. return hr;
  339. wszRet = (WCHAR*)new BYTE[dwSize];
  340. if (!wszRet)
  341. return E_OUTOFMEMORY;
  342. hr = m__dxj_DirectPlayAddress->GetComponentByName(wszComponent, wszRet, &dwSize, &dwDataType);
  343. if (FAILED(hr))
  344. return hr;
  345. *sValue = SysAllocString(wszRet);
  346. SAFE_DELETE(wszRet);
  347. }
  348. __except(EXCEPTION_EXECUTE_HANDLER)
  349. {
  350. return E_FAIL;
  351. }
  352. return S_OK;
  353. }