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.

242 lines
5.0 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1994-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: factory.c
  6. * Content: DirectDrawFactory implementation
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 22-oct-97 jeffno initial implementation
  11. *
  12. ***************************************************************************/
  13. #include "ddrawpr.h"
  14. HRESULT InternalCreateDDFactory2(void ** ppvObj, IUnknown * pUnkOuter)
  15. {
  16. LPDDFACTORY2 lpFac = NULL;
  17. DDASSERT(ppvObj);
  18. if (pUnkOuter)
  19. {
  20. return CLASS_E_NOAGGREGATION;
  21. }
  22. /*
  23. * If any allocations are added to this function, make sure to update the
  24. * cleanup code in classfac.c
  25. */
  26. lpFac = MemAlloc(sizeof(DDFACTORY2));
  27. if (!lpFac)
  28. {
  29. return DDERR_OUTOFMEMORY;
  30. }
  31. lpFac->lpVtbl = &ddFactory2Callbacks;
  32. lpFac->dwRefCnt = 0;
  33. *ppvObj = (IUnknown*) lpFac;
  34. return DD_OK;
  35. }
  36. /*
  37. * DDFac2_QueryInterface
  38. */
  39. HRESULT DDAPI DDFac2_QueryInterface(
  40. LPDIRECTDRAWFACTORY2 lpDDFac,
  41. REFIID riid,
  42. LPVOID FAR * ppvObj )
  43. {
  44. LPDDFACTORY2 this;
  45. ENTER_DDRAW();
  46. DPF(2,A,"ENTERAPI: DDFac2_QueryInterface");
  47. /*
  48. * validate parms
  49. */
  50. TRY
  51. {
  52. this = (LPDDFACTORY2) lpDDFac;
  53. if( !VALID_DIRECTDRAWFACTORY2_PTR( this ) )
  54. {
  55. LEAVE_DDRAW();
  56. return DDERR_INVALIDOBJECT;
  57. }
  58. if( !VALID_PTR_PTR( ppvObj ) )
  59. {
  60. DPF( 1, "Invalid clipper pointer" );
  61. LEAVE_DDRAW();
  62. return (DWORD) DDERR_INVALIDPARAMS;
  63. }
  64. if( !VALIDEX_IID_PTR( riid ) )
  65. {
  66. DPF_ERR( "Invalid IID pointer" );
  67. LEAVE_DDRAW();
  68. return (DWORD) DDERR_INVALIDPARAMS;
  69. }
  70. *ppvObj = NULL;
  71. }
  72. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  73. {
  74. DPF_ERR( "Exception encountered validating parameters" );
  75. LEAVE_DDRAW();
  76. return DDERR_INVALIDPARAMS;
  77. }
  78. /*
  79. * check guids
  80. */
  81. if( IsEqualIID(riid, &IID_IUnknown) ||
  82. IsEqualIID(riid, &IID_IDirectDrawFactory2) )
  83. {
  84. ((IUnknown*)this)->lpVtbl->AddRef((IUnknown*)this);
  85. *ppvObj = (LPVOID) this;
  86. LEAVE_DDRAW();
  87. return DD_OK;
  88. }
  89. LEAVE_DDRAW();
  90. return E_NOINTERFACE;
  91. } /* DDFac2_QueryInterface */
  92. #undef DPF_MODNAME
  93. #define DPF_MODNAME "DDFactory2::AddRef"
  94. /*
  95. * DDFac2_AddRef
  96. */
  97. DWORD DDAPI DDFac2_AddRef( LPDIRECTDRAWFACTORY2 lpDDFac )
  98. {
  99. LPDDFACTORY2 this;
  100. ENTER_DDRAW();
  101. DPF(2,A,"ENTERAPI: DDFac2_AddRef");
  102. /*
  103. * validate parms
  104. */
  105. TRY
  106. {
  107. this = (LPDDFACTORY2) lpDDFac;
  108. if( !VALID_DIRECTDRAWFACTORY2_PTR( this ) )
  109. {
  110. LEAVE_DDRAW();
  111. return 0;
  112. }
  113. }
  114. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  115. {
  116. DPF_ERR( "Exception encountered validating parameters" );
  117. LEAVE_DDRAW();
  118. return 0;
  119. }
  120. /*
  121. * update reference count
  122. */
  123. this->dwRefCnt++;
  124. DPF( 5, "DDFactory %08lx addrefed, refcnt = %ld", this, this->dwRefCnt );
  125. LEAVE_DDRAW();
  126. return this->dwRefCnt;
  127. } /* DDFac2_AddRef */
  128. #undef DPF_MODNAME
  129. #define DPF_MODNAME "DDFactory2::Release"
  130. ULONG DDAPI DDFac2_Release( LPDIRECTDRAWFACTORY2 lpDDFac )
  131. {
  132. LPDDFACTORY2 this;
  133. ENTER_DDRAW();
  134. DPF(2,A,"ENTERAPI: DDFac2_Release");
  135. /*
  136. * validate parms
  137. */
  138. TRY
  139. {
  140. this = (LPDDFACTORY2) lpDDFac;
  141. if( !VALID_DIRECTDRAWFACTORY2_PTR( this ) )
  142. {
  143. LEAVE_DDRAW();
  144. return 0;
  145. }
  146. }
  147. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  148. {
  149. DPF_ERR( "Exception encountered validating parameters" );
  150. LEAVE_DDRAW();
  151. return 0;
  152. }
  153. /*
  154. * update reference count
  155. */
  156. this->dwRefCnt--;
  157. DPF( 5, "DDFactory %08lx releaseed, refcnt = %ld", this, this->dwRefCnt );
  158. if (this->dwRefCnt == 0)
  159. {
  160. this->lpVtbl = 0;
  161. MemFree(this);
  162. LEAVE_DDRAW();
  163. return 0;
  164. }
  165. LEAVE_DDRAW();
  166. return this->dwRefCnt;
  167. } /* DDFac2_Release */
  168. HRESULT DDAPI DDFac2_CreateDirectDraw(
  169. LPDIRECTDRAWFACTORY2 lpDDFac,
  170. GUID FAR*rDeviceGuid,
  171. HWND hWnd,
  172. DWORD dwCoopLevelFlags,
  173. DWORD dwFlags,
  174. IUnknown FAR *pUnkOuter,
  175. IDirectDraw4 FAR **ppDDraw)
  176. {
  177. LPDIRECTDRAW lpDD;
  178. HRESULT hr = DirectDrawCreate( rDeviceGuid, &lpDD, pUnkOuter );
  179. lpDDFac;
  180. DPF(2,A,"ENTERAPI: DDFac2_CreateDirectDraw");
  181. if( SUCCEEDED(hr) )
  182. {
  183. hr = lpDD->lpVtbl->QueryInterface(lpDD,&IID_IDirectDraw4,(void**) ppDDraw);
  184. lpDD->lpVtbl->Release(lpDD);
  185. if( SUCCEEDED(hr) )
  186. {
  187. hr = (*ppDDraw)->lpVtbl->SetCooperativeLevel(*ppDDraw, hWnd, dwCoopLevelFlags);
  188. }
  189. }
  190. return hr;
  191. } /* DDFac2_CreateDirectDraw */
  192. HRESULT DDAPI DDFac2_DirectDrawEnumerate(LPDIRECTDRAWFACTORY2 lpDDFac, LPDDENUMCALLBACKEX lpCallback, LPVOID lpContext , DWORD dwFlags)
  193. {
  194. DPF(2,A,"ENTERAPI: DDFac2_DirectDrawEnumerate");
  195. return DirectDrawEnumerateExA(lpCallback, lpContext, dwFlags);
  196. } /* DDFac2_DirectDrawEnumerate */