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.

355 lines
9.6 KiB

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