Source code of Windows XP (NT5)
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.

374 lines
9.8 KiB

  1. /*****************************************************************************
  2. *
  3. * DICF.c
  4. *
  5. * Copyright (c) 1996 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * Abstract:
  8. *
  9. * DirectInput ClassFactory.
  10. *
  11. * Contents:
  12. *
  13. * IClassFactory::CreateInstance
  14. * IClassFactory::LockServer
  15. *
  16. *****************************************************************************/
  17. #include "dinputpr.h"
  18. /*****************************************************************************
  19. *
  20. * The sqiffle for this file.
  21. *
  22. *****************************************************************************/
  23. #define sqfl sqflFactory
  24. /*****************************************************************************
  25. *
  26. * Declare the interfaces we will be providing.
  27. *
  28. *****************************************************************************/
  29. Primary_Interface(CDIFactory, IClassFactory);
  30. Interface_Template_Begin(CDIFactory)
  31. Primary_Interface_Template(CDIFactory, IClassFactory)
  32. Interface_Template_End(CDIFactory)
  33. /*****************************************************************************
  34. *
  35. * @doc INTERNAL
  36. *
  37. * @struct CDIFactory |
  38. *
  39. * The DirectInput <i IClassFactory>, which is how you create an
  40. * <i IDirectInput> object.
  41. * There really isn't anything interesting in the structure
  42. * itself.
  43. *
  44. * @field IClassFactory | cf |
  45. *
  46. * ClassFactory object (containing vtbl).
  47. *
  48. * @field CREATEFUNC | pfnCreate |
  49. *
  50. * Function that creates new objects.
  51. *
  52. *****************************************************************************/
  53. typedef struct CDIFactory {
  54. /* Supported interfaces */
  55. IClassFactory cf;
  56. CREATEFUNC pfnCreate;
  57. } CDIFactory, DCF, *PDCF;
  58. typedef IClassFactory CF, *PCF;
  59. #define ThisClass CDIFactory
  60. #define ThisInterface IClassFactory
  61. #define ThisInterfaceT IClassFactory
  62. /*****************************************************************************
  63. *
  64. * @doc EXTERNAL
  65. *
  66. * @method HRESULT | IClassFactory | QueryInterface |
  67. *
  68. * Gives a client access to other interfaces on an object.
  69. *
  70. * @cwrap LPCLASSFACTORY | lpClassFactory
  71. *
  72. * @parm IN REFIID | riid |
  73. *
  74. * The requested interface's IID.
  75. *
  76. * @parm OUT LPVOID * | ppvObj |
  77. *
  78. * Receives a pointer to the obtained interface.
  79. *
  80. * @returns
  81. *
  82. * Returns a COM error code.
  83. *
  84. * @xref OLE documentation for <mf IUnknown::QueryInterface>.
  85. *
  86. *****************************************************************************
  87. *
  88. * @doc EXTERNAL
  89. *
  90. * @method HRESULT | IClassFactory | AddRef |
  91. *
  92. * Increments the reference count for the interface.
  93. *
  94. * @cwrap LPCLASSFACTORY | lpClassFactory
  95. *
  96. * @returns
  97. *
  98. * Returns the object reference count.
  99. *
  100. * @xref OLE documentation for <mf IUnknown::AddRef>.
  101. *
  102. *****************************************************************************
  103. *
  104. * @doc EXTERNAL
  105. *
  106. * @method HRESULT | IClassFactory | Release |
  107. *
  108. * Decrements the reference count for the interface.
  109. * If the reference count on the object falls to zero,
  110. * the object is freed from memory.
  111. *
  112. * @cwrap LPCLASSFACTORY | lpClassFactory
  113. *
  114. * @returns
  115. *
  116. * Returns the object reference count.
  117. *
  118. * @xref OLE documentation for <mf IUnknown::Release>.
  119. *
  120. *****************************************************************************
  121. *
  122. * @doc INTERNAL
  123. *
  124. * @method HRESULT | IClassFactory | QIHelper |
  125. *
  126. * We don't have any dynamic interfaces and simply forward
  127. * to <f Common_QIHelper>.
  128. *
  129. * @parm IN REFIID | riid |
  130. *
  131. * The requested interface's IID.
  132. *
  133. * @parm OUT LPVOID * | ppvObj |
  134. *
  135. * Receives a pointer to the obtained interface.
  136. *
  137. *****************************************************************************
  138. *
  139. * @doc INTERNAL
  140. *
  141. * @func HRESULT | IClassFactory_AppFinalize |
  142. *
  143. * We don't have any weak pointers, so we can just
  144. * forward to <f Common_Finalize>.
  145. *
  146. * @parm PV | pvObj |
  147. *
  148. * Object being released from the application's perspective.
  149. *
  150. *****************************************************************************
  151. *
  152. * @doc INTERNAL
  153. *
  154. * @func HRESULT | IClassFactory_Finalize |
  155. *
  156. * We don't have any instance data, so we can just
  157. * forward to <f Common_Finalize>.
  158. *
  159. * @parm PV | pvObj |
  160. *
  161. * Object being released.
  162. *
  163. *****************************************************************************/
  164. #ifdef DEBUG
  165. Default_QueryInterface(CDIFactory)
  166. Default_AddRef(CDIFactory)
  167. Default_Release(CDIFactory)
  168. #else
  169. #define CDIFactory_QueryInterface Common_QueryInterface
  170. #define CDIFactory_AddRef Common_AddRef
  171. #define CDIFactory_Release Common_Release
  172. #endif
  173. #define CDIFactory_QIHelper Common_QIHelper
  174. #define CDIFactory_AppFinalize Common_AppFinalize
  175. #define CDIFactory_Finalize Common_Finalize
  176. /*****************************************************************************
  177. *
  178. * @doc EXTERNAL
  179. *
  180. * @method HRESULT | IClassFactory | CreateInstance |
  181. *
  182. * This function creates a new DirectInput object with
  183. * the specified interface.
  184. *
  185. * @cwrap LPCLASSFACTORY | lpClassFactory
  186. *
  187. * @parm IN LPUNKNOWN | punkOuter | Pointer to controlling unknown.
  188. * Aggregation is not supported in this version of DirectInput,
  189. * so the value "should" be 0.
  190. *
  191. * @parm IN REFIID | riid |
  192. * Desired interface. This parameter "must" point to a valid
  193. * interface identifier.
  194. *
  195. * @parm OUT LPVOID * | ppvOut |
  196. * Points to where to return the pointer to the created interface,
  197. * if successful.
  198. *
  199. * @returns
  200. *
  201. * Returns a COM error code. The following error codes are
  202. * intended to be illustrative and not necessarily comprehensive.
  203. *
  204. * <c S_OK>: The operation completed successfully.
  205. *
  206. * <c E_INVALIDARG>: The
  207. * <p ppvOut> parameter is not a valid pointer.
  208. *
  209. * <c CLASS_E_NOAGGREGATION>:
  210. * Aggregation not supported.
  211. *
  212. * <c E_OUTOFMEMORY>:
  213. * Out of memory.
  214. *
  215. * <c E_NOINTERFACE>:
  216. * The specified interface is not supported.
  217. *
  218. * @xref OLE documentation for <mf IClassFactory::CreateInstance>.
  219. *
  220. *****************************************************************************/
  221. STDMETHODIMP
  222. CDIFactory_CreateInstance(PCF pcf, PUNK punkOuter, RIID riid, PPV ppvObj)
  223. {
  224. HRESULT hres;
  225. EnterProcR(IClassFactory::CreateInstance,
  226. (_ "ppGp", pcf, punkOuter, riid, ppvObj));
  227. if (SUCCEEDED(hres = hresPv(pcf))) {
  228. PDCF this;
  229. if (Num_Interfaces(CDIFactory) == 1) {
  230. this = _thisPvNm(pcf, cf);
  231. } else {
  232. this = _thisPv(pcf);
  233. }
  234. /*
  235. * All parameters will be validated by pfnCreate.
  236. */
  237. hres = this->pfnCreate(punkOuter, riid, ppvObj);
  238. }
  239. ExitOleProcPpvR(ppvObj);
  240. return hres;
  241. }
  242. /*****************************************************************************
  243. *
  244. * @doc EXTERNAL
  245. *
  246. * @method HRESULT | IClassFactory | LockServer |
  247. *
  248. * This function increments or decrements the DLL lock
  249. * count. While the DLL lock count is nonzero,
  250. * it will not be removed from memory.
  251. *
  252. * @cwrap LPCLASSFACTORY | lpClassFactory
  253. *
  254. * @parm BOOL | fLock |
  255. * If <c TRUE>, increments the lock count.
  256. * If <c FALSE>, decrements the lock count.
  257. *
  258. * @returns
  259. * Returns a COM error code. The following error codes are
  260. * intended to be illustrative and not necessarily comprehensive.
  261. *
  262. * <c S_OK>: The operation completed successfully.
  263. *
  264. * <c E_OUTOFMEMORY>: Out of memory.
  265. *
  266. * @xref OLE documentation for <mf IClassFactory::LockServer>.
  267. *
  268. *****************************************************************************/
  269. STDMETHODIMP
  270. CDIFactory_LockServer(PCF pcf, BOOL fLock)
  271. {
  272. HRESULT hres;
  273. EnterProcR(IClassFactory::LockServer, (_ "px", pcf, fLock));
  274. if (SUCCEEDED(hres = hresPv(pcf))) {
  275. if (fLock) {
  276. DllAddRef();
  277. } else {
  278. DllRelease();
  279. }
  280. }
  281. ExitOleProc();
  282. return hres;
  283. }
  284. /*****************************************************************************
  285. *
  286. * @doc INTERNAL
  287. *
  288. * @mfunc HRESULT | IClassFactory | New |
  289. *
  290. * Create a new instance of the class factory.
  291. *
  292. * @parm IN PUNK | punkOuter |
  293. *
  294. * Controlling unknown for aggregation.
  295. *
  296. * @parm IN RIID | riid |
  297. * Desired interface to new object.
  298. *
  299. * @parm OUT PPV | ppvObj |
  300. * Output pointer for new object.
  301. *
  302. * @returns
  303. *
  304. * Standard OLE <t HRESULT>.
  305. *
  306. *****************************************************************************/
  307. STDMETHODIMP
  308. CDIFactory_New(CREATEFUNC pfnCreate, RIID riid, PPV ppvObj)
  309. {
  310. HRESULT hres;
  311. EnterProcR(IClassFactory::<constructor>, (_ "G", riid));
  312. hres = Common_NewRiid(CDIFactory, 0, riid, ppvObj);
  313. if (SUCCEEDED(hres)) {
  314. PDCF this;
  315. if (Num_Interfaces(CDIFactory) == 1) {
  316. /* We can go directly in because we cannot be aggregated */
  317. this = *ppvObj;
  318. } else {
  319. this = _thisPv(*ppvObj);
  320. }
  321. this->pfnCreate = pfnCreate;
  322. }
  323. ExitOleProcPpvR(ppvObj);
  324. return hres;
  325. }
  326. /*****************************************************************************
  327. *
  328. * The long-awaited vtbl.
  329. *
  330. *****************************************************************************/
  331. #pragma BEGIN_CONST_DATA
  332. #define CDIFactory_Signature 0x20204643 /* "CF " */
  333. Primary_Interface_Begin(CDIFactory, IClassFactory)
  334. CDIFactory_CreateInstance,
  335. CDIFactory_LockServer,
  336. Primary_Interface_End(CDIFactory, IClassFactory)