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.

370 lines
13 KiB

  1. //---------------------------------------------------------------------------
  2. // CMSR2C.cpp : CVDCursorFromRowset implementation
  3. //
  4. // Copyright (c) 1996 Microsoft Corporation, All Rights Reserved
  5. // Developed by Sheridan Software Systems, Inc.
  6. //---------------------------------------------------------------------------
  7. #include "stdafx.h"
  8. #include "MSR2C.h"
  9. #include "CMSR2C.h"
  10. #include "Notifier.h"
  11. #include "RSColumn.h"
  12. #include "RSSource.h"
  13. #include "CursMain.h"
  14. SZTHISFILE
  15. //=--------------------------------------------------------------------------=
  16. // CreateInstance - Same params as IClassFactory::CreateInstance
  17. //
  18. // Desc: instantiates an CVDCursorFromRowset object, returning an interface
  19. // pointer.
  20. // Parms: riid - ID identifying the interface the caller
  21. // desires to have for the new object.
  22. // ppvObj - pointer in which to store the desired
  23. // interface pointer for the new object.
  24. // Return: HRESULT - NOERROR if successful, otherwise
  25. // E_NOINTERFACE if we cannot support the
  26. // requested interface.
  27. //
  28. HRESULT CVDCursorFromRowset::CreateInstance(LPUNKNOWN pUnkOuter,
  29. REFIID riid,
  30. LPVOID * ppvObj)
  31. {
  32. if (!ppvObj)
  33. return E_INVALIDARG;
  34. *ppvObj=NULL;
  35. if (pUnkOuter)
  36. {
  37. //If aggregating then they have to ask for IUnknown
  38. if (!DO_GUIDS_MATCH(riid, IID_IUnknown))
  39. return E_INVALIDARG;
  40. }
  41. //Create the object
  42. CVDCursorFromRowset * pNewObj = new CVDCursorFromRowset(pUnkOuter);
  43. if (NULL==pNewObj)
  44. return E_OUTOFMEMORY;
  45. //Get interface from private unknown - needed for aggreagation support
  46. HRESULT hr=pNewObj->m_UnkPrivate.QueryInterface(riid, ppvObj);
  47. if FAILED(hr)
  48. delete pNewObj;
  49. return hr;
  50. }
  51. //=--------------------------------------------------------------------------=
  52. // CVDCursorPosition - Constructor
  53. //
  54. CVDCursorFromRowset::CVDCursorFromRowset(LPUNKNOWN pUnkOuter)
  55. {
  56. m_pUnkOuter = pUnkOuter;
  57. VDUpdateObjectCount(1); // update global object counter to prevent dll from being unloaded
  58. }
  59. //=--------------------------------------------------------------------------=
  60. // CVDCursorPosition - Destructor
  61. //
  62. CVDCursorFromRowset::~CVDCursorFromRowset()
  63. {
  64. VDUpdateObjectCount(-1); // update global object counter to allow dll to be unloaded
  65. }
  66. ///////////////////////////////////////////////////////////////////
  67. // Name: QueryInterface
  68. // Desc: allows a client to ask our object if we support a
  69. // particular method.
  70. // Parms: [in] riid - ID of method the client is querying for.
  71. // [out] ppv - pointer to the interface requested.
  72. // Return: HRESULT - NOERROR if a pointer to the interface will
  73. // be returned, or E_NOINTERFACE if it cannot.
  74. ////////////////////////////////////////////////////////////////////
  75. STDMETHODIMP CVDCursorFromRowset::QueryInterface(REFIID riid, void** ppv)
  76. {
  77. if (m_pUnkOuter)
  78. return m_pUnkOuter->QueryInterface(riid, ppv);
  79. else
  80. return m_UnkPrivate.QueryInterface(riid, ppv);
  81. }
  82. ////////////////////////////////////////////////////////////////////
  83. // Name: AddRef
  84. // Desc: increment the reference count on our object.
  85. // Parms: none
  86. // Return: current reference count.
  87. ////////////////////////////////////////////////////////////////////
  88. STDMETHODIMP_(ULONG) CVDCursorFromRowset::AddRef(void)
  89. {
  90. if (m_pUnkOuter)
  91. return m_pUnkOuter->AddRef();
  92. else
  93. return m_UnkPrivate.AddRef();
  94. }
  95. ////////////////////////////////////////////////////////////////////
  96. // Name: Release
  97. // Desc: decrement the reference count on our object. If the
  98. // count has gone to 0, destroy the object.
  99. // Parms: none
  100. // Return: current reference count.
  101. ////////////////////////////////////////////////////////////////////
  102. STDMETHODIMP_(ULONG) CVDCursorFromRowset::Release(void)
  103. {
  104. if (m_pUnkOuter)
  105. return m_pUnkOuter->Release();
  106. else
  107. return m_UnkPrivate.Release();
  108. }
  109. //=--------------------------------------------------------------------------=
  110. // GetCursor - Get cursor from rowset
  111. //=--------------------------------------------------------------------------=
  112. STDMETHODIMP CVDCursorFromRowset::GetCursor(IRowset * pRowset,
  113. ICursor ** ppCursor,
  114. LCID lcid)
  115. {
  116. return CVDCursorMain::Create(pRowset, ppCursor, lcid);
  117. }
  118. //=--------------------------------------------------------------------------=
  119. // GetCursor - Get cursor from row position
  120. //=--------------------------------------------------------------------------=
  121. STDMETHODIMP CVDCursorFromRowset::GetCursor(IRowPosition * pRowPosition,
  122. ICursor ** ppCursor,
  123. LCID lcid)
  124. {
  125. return CVDCursorMain::Create(pRowPosition, ppCursor, lcid);
  126. }
  127. //=--------------------------------------------------------------------------=
  128. // CVDCursorFromRowset::CPrivateUnknownObject::m_pMainUnknown
  129. //=--------------------------------------------------------------------------=
  130. // this method is used when we're sitting in the private unknown object,
  131. // and we need to get at the pointer for the main unknown. basically, it's
  132. // a little better to do this pointer arithmetic than have to store a pointer
  133. // to the parent, etc.
  134. //
  135. inline CVDCursorFromRowset *CVDCursorFromRowset::CPrivateUnknownObject::m_pMainUnknown
  136. (
  137. void
  138. )
  139. {
  140. return (CVDCursorFromRowset *)((LPBYTE)this - offsetof(CVDCursorFromRowset, m_UnkPrivate));
  141. }
  142. //=--------------------------------------------------------------------------=
  143. // CVDCursorFromRowset::CPrivateUnknownObject::QueryInterface
  144. //=--------------------------------------------------------------------------=
  145. // this is the non-delegating internal QI routine.
  146. //
  147. // Parameters:
  148. // REFIID - [in] interface they want
  149. // void ** - [out] where they want to put the resulting object ptr.
  150. //
  151. // Output:
  152. // HRESULT - S_OK, E_NOINTERFACE
  153. //
  154. // Notes:
  155. //
  156. STDMETHODIMP CVDCursorFromRowset::CPrivateUnknownObject::QueryInterface
  157. (
  158. REFIID riid,
  159. void **ppvObjOut
  160. )
  161. {
  162. if (!ppvObjOut)
  163. return E_INVALIDARG;
  164. *ppvObjOut = NULL;
  165. if (DO_GUIDS_MATCH(riid, IID_IUnknown))
  166. {
  167. m_cRef++;
  168. *ppvObjOut = (IUnknown *)this;
  169. }
  170. else
  171. if (DO_GUIDS_MATCH(riid, IID_ICursorFromRowset))
  172. {
  173. m_pMainUnknown()->AddRef();
  174. *ppvObjOut = m_pMainUnknown();
  175. }
  176. else
  177. if (DO_GUIDS_MATCH(riid, IID_ICursorFromRowPosition))
  178. {
  179. m_pMainUnknown()->AddRef();
  180. *ppvObjOut = (ICursorFromRowPosition*)m_pMainUnknown();
  181. }
  182. return *ppvObjOut ? S_OK : E_NOINTERFACE;
  183. }
  184. //=--------------------------------------------------------------------------=
  185. // CVDCursorFromRowset::CPrivateUnknownObject::AddRef
  186. //=--------------------------------------------------------------------------=
  187. // adds a tick to the current reference count.
  188. //
  189. // Output:
  190. // ULONG - the new reference count
  191. //
  192. // Notes:
  193. //
  194. ULONG CVDCursorFromRowset::CPrivateUnknownObject::AddRef
  195. (
  196. void
  197. )
  198. {
  199. return ++m_cRef;
  200. }
  201. //=--------------------------------------------------------------------------=
  202. // CVDCursorFromRowset::CPrivateUnknownObject::Release
  203. //=--------------------------------------------------------------------------=
  204. // removes a tick from the count, and delets the object if necessary
  205. //
  206. // Output:
  207. // ULONG - remaining refs
  208. //
  209. // Notes:
  210. //
  211. ULONG CVDCursorFromRowset::CPrivateUnknownObject::Release
  212. (
  213. void
  214. )
  215. {
  216. ULONG cRef = --m_cRef;
  217. if (!m_cRef)
  218. delete m_pMainUnknown();
  219. return cRef;
  220. }
  221. //=--------------------------------------------------------------------------=
  222. // VDGetICursorFromIRowset
  223. //=--------------------------------------------------------------------------=
  224. // MSR2C entry point
  225. //
  226. HRESULT WINAPI VDGetICursorFromIRowset(IRowset * pRowset,
  227. ICursor ** ppCursor,
  228. LCID lcid)
  229. {
  230. // call update object count to initialize g_pMalloc if not already initialized
  231. VDUpdateObjectCount(1);
  232. HRESULT hr = CVDCursorMain::Create(pRowset, ppCursor, lcid);
  233. // maintain correct object count (object count is incremented in the constructor
  234. // of CVDCursorMain)
  235. VDUpdateObjectCount(-1);
  236. return hr;
  237. }
  238. // object construction/destruction counters (debug only)
  239. //
  240. #ifdef _DEBUG
  241. int g_cVDNotifierCreated; // CVDNotifier
  242. int g_cVDNotifierDestroyed;
  243. int g_cVDNotifyDBEventsConnPtCreated; // CVDNotifyDBEventsConnPt
  244. int g_cVDNotifyDBEventsConnPtDestroyed;
  245. int g_cVDNotifyDBEventsConnPtContCreated; // CVDNotifyDBEventsConnPtCont
  246. int g_cVDNotifyDBEventsConnPtContDestroyed;
  247. int g_cVDEnumConnPointsCreated; // CVDEnumConnPoints
  248. int g_cVDEnumConnPointsDestroyed;
  249. int g_cVDRowsetColumnCreated; // CVDRowsetColumn
  250. int g_cVDRowsetColumnDestroyed;
  251. int g_cVDRowsetSourceCreated; // CVDRowsetSource
  252. int g_cVDRowsetSourceDestroyed;
  253. int g_cVDCursorMainCreated; // CVDCursorMain
  254. int g_cVDCursorMainDestroyed;
  255. int g_cVDCursorPositionCreated; // CVDCursorPosition
  256. int g_cVDCursorPositionDestroyed;
  257. int g_cVDCursorBaseCreated; // CVDCursorBase
  258. int g_cVDCursorBaseDestroyed;
  259. int g_cVDCursorCreated; // CVDCursor
  260. int g_cVDCursorDestroyed;
  261. int g_cVDMetadataCursorCreated; // CVDMetadataCursor
  262. int g_cVDMetadataCursorDestroyed;
  263. int g_cVDEntryIDDataCreated; // CVDEntryIDData
  264. int g_cVDEntryIDDataDestroyed;
  265. int g_cVDStreamCreated; // CVDStream
  266. int g_cVDStreamDestroyed;
  267. int g_cVDColumnUpdateCreated; // CVDColumnUpdate
  268. int g_cVDColumnUpdateDestroyed;
  269. #endif // _DEBUG
  270. // dump oject counters
  271. //
  272. #ifdef _DEBUG
  273. void DumpObjectCounters()
  274. {
  275. CHAR str[256];
  276. OutputDebugString("MSR2C Objects-\n");
  277. wsprintf(str, "CVDNotifier: Created = %d, Destroyed = %d, Equal = %d.\n",
  278. g_cVDNotifierCreated, g_cVDNotifierDestroyed,
  279. g_cVDNotifierCreated == g_cVDNotifierDestroyed);
  280. OutputDebugString(str);
  281. wsprintf(str, "CVDNotifyDBEventsConnPt: Created = %d, Destroyed = %d, Equal = %d.\n",
  282. g_cVDNotifyDBEventsConnPtCreated, g_cVDNotifyDBEventsConnPtDestroyed,
  283. g_cVDNotifyDBEventsConnPtCreated == g_cVDNotifyDBEventsConnPtDestroyed);
  284. OutputDebugString(str);
  285. wsprintf(str, "CVDNotifyDBEventsConnPtCont: Created = %d, Destroyed = %d, Equal = %d.\n",
  286. g_cVDNotifyDBEventsConnPtContCreated, g_cVDNotifyDBEventsConnPtContDestroyed,
  287. g_cVDNotifyDBEventsConnPtContCreated == g_cVDNotifyDBEventsConnPtContDestroyed);
  288. OutputDebugString(str);
  289. wsprintf(str, "CVDEnumConnPoints: Created = %d, Destroyed = %d, Equal = %d.\n",
  290. g_cVDEnumConnPointsCreated, g_cVDEnumConnPointsDestroyed,
  291. g_cVDEnumConnPointsCreated == g_cVDEnumConnPointsDestroyed);
  292. OutputDebugString(str);
  293. wsprintf(str, "CVDRowsetColumn: Created = %d, Destroyed = %d, Equal = %d.\n",
  294. g_cVDRowsetColumnCreated, g_cVDRowsetColumnDestroyed,
  295. g_cVDRowsetColumnCreated == g_cVDRowsetColumnDestroyed);
  296. OutputDebugString(str);
  297. wsprintf(str, "CVDRowsetSource: Created = %d, Destroyed = %d, Equal = %d.\n",
  298. g_cVDRowsetSourceCreated, g_cVDRowsetSourceDestroyed,
  299. g_cVDRowsetSourceCreated == g_cVDRowsetSourceDestroyed);
  300. OutputDebugString(str);
  301. wsprintf(str, "CVDCursorMain: Created = %d, Destroyed = %d, Equal = %d.\n",
  302. g_cVDCursorMainCreated, g_cVDCursorMainDestroyed,
  303. g_cVDCursorMainCreated == g_cVDCursorMainDestroyed);
  304. OutputDebugString(str);
  305. wsprintf(str, "CVDCursorPosition: Created = %d, Destroyed = %d, Equal = %d.\n",
  306. g_cVDCursorPositionCreated, g_cVDCursorPositionDestroyed,
  307. g_cVDCursorPositionCreated == g_cVDCursorPositionDestroyed);
  308. OutputDebugString(str);
  309. wsprintf(str, "CVDCursorBase: Created = %d, Destroyed = %d, Equal = %d.\n",
  310. g_cVDCursorBaseCreated, g_cVDCursorBaseDestroyed,
  311. g_cVDCursorBaseCreated == g_cVDCursorBaseDestroyed);
  312. OutputDebugString(str);
  313. wsprintf(str, "CVDCursor: Created = %d, Destroyed = %d, Equal = %d.\n",
  314. g_cVDCursorCreated, g_cVDCursorDestroyed,
  315. g_cVDCursorCreated == g_cVDCursorDestroyed);
  316. OutputDebugString(str);
  317. wsprintf(str, "CVDMetadataCursor: Created = %d, Destroyed = %d, Equal = %d.\n",
  318. g_cVDMetadataCursorCreated, g_cVDMetadataCursorDestroyed,
  319. g_cVDMetadataCursorCreated == g_cVDMetadataCursorDestroyed);
  320. OutputDebugString(str);
  321. wsprintf(str, "CVDEntryIDData: Created = %d, Destroyed = %d, Equal = %d.\n",
  322. g_cVDEntryIDDataCreated, g_cVDEntryIDDataDestroyed,
  323. g_cVDEntryIDDataCreated == g_cVDEntryIDDataDestroyed);
  324. OutputDebugString(str);
  325. wsprintf(str, "CVDStream: Created = %d, Destroyed = %d, Equal = %d.\n",
  326. g_cVDStreamCreated, g_cVDStreamDestroyed,
  327. g_cVDStreamCreated == g_cVDStreamDestroyed);
  328. OutputDebugString(str);
  329. wsprintf(str, "CVDColumnUpdate: Created = %d, Destroyed = %d, Equal = %d.\n",
  330. g_cVDColumnUpdateCreated, g_cVDColumnUpdateDestroyed,
  331. g_cVDColumnUpdateCreated == g_cVDColumnUpdateDestroyed);
  332. OutputDebugString(str);
  333. }
  334. #endif // _DEBUG