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.

290 lines
7.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1997, Microsoft Corporation
  4. //
  5. // File: dberror.hxx
  6. //
  7. // Contents: Ole DB error object to implement OLE DB error interfaces.
  8. //
  9. // Classes: CCIOleDBError
  10. //
  11. // History: 28-Apr-97 KrishnaN Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. //
  16. // NOTE: High nibble is reserved by IDENTIFIER_SDK_MASK. Second highest
  17. // nibble is used by Monarch, so we will use the third highest
  18. // nibble to identify our errors.
  19. //
  20. const DWORD IDENTIFIER_CI_ERROR = 0x00800000;
  21. // CLSID_CI_PROVIDER
  22. // {F9AE8980-7E52-11d0-8964-00C04FD611D7}
  23. const GUID CLSID_CI_PROVIDER =
  24. {0xF9AE8980, 0x7E52, 0x11d0, 0x89, 0x64, 0x00, 0xC0, 0x4F, 0xD6, 0x11, 0xD7};
  25. // CLSID_CI_ERROR
  26. // {F9AE8981-7E52-11d0-8964-00C04FD611D7}
  27. const GUID CLSID_CI_ERROR =
  28. {0xF9AE8981, 0x7E52, 0x11d0, 0x89, 0x64, 0x00, 0xC0, 0x4F, 0xD6, 0x11, 0xD7};
  29. //+-------------------------------------------------------------------------
  30. //
  31. // Class: CErrorLookupCF
  32. //
  33. // Purpose: Class factory for CIndexer class
  34. //
  35. // History: 25-Mar-97 KrishnaN Created
  36. //
  37. //--------------------------------------------------------------------------
  38. class CErrorLookupCF : public IClassFactory
  39. {
  40. public:
  41. CErrorLookupCF();
  42. //
  43. // From IUnknown
  44. //
  45. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID *ppiuk );
  46. STDMETHOD_(ULONG, AddRef) (THIS);
  47. STDMETHOD_(ULONG, Release) (THIS);
  48. //
  49. // From IClassFactory
  50. //
  51. STDMETHOD(CreateInstance) ( IUnknown * pUnkOuter,
  52. REFIID riid, void * * ppvObject );
  53. STDMETHOD(LockServer) ( BOOL fLock );
  54. protected:
  55. friend SCODE STDMETHODCALLTYPE DllGetClassObject( REFCLSID cid,
  56. REFIID iid, void** ppvObj );
  57. virtual ~CErrorLookupCF();
  58. long _cRefs;
  59. };
  60. //+-------------------------------------------------------------------------
  61. //
  62. // Class: CErrorLookup
  63. //
  64. // Purpose: Implements IErrorLookup
  65. //
  66. // History: 28-Apr-97 KrishnaN Created
  67. //
  68. //--------------------------------------------------------------------------
  69. class CErrorLookup : public IErrorLookup
  70. {
  71. public:
  72. CErrorLookup() : _cRefs (1)
  73. {
  74. }
  75. //
  76. // IUnknown methods.
  77. //
  78. STDMETHOD(QueryInterface) ( THIS_ REFIID riid, LPVOID *ppiuk );
  79. STDMETHOD_(ULONG, AddRef) (THIS);
  80. STDMETHOD_(ULONG, Release) (THIS);
  81. //
  82. // IErrorLookup members
  83. //
  84. // GetErrorDescription Method
  85. STDMETHOD(GetErrorDescription)(HRESULT hrError,
  86. DWORD dwLookupId,
  87. DISPPARAMS* pdispparams,
  88. LCID lcid,
  89. BSTR* ppwszSource,
  90. BSTR* ppwszDescription);
  91. // GetHelpInfo Method
  92. STDMETHOD(GetHelpInfo)(HRESULT hrError,
  93. DWORD dwLookupId,
  94. LCID lcid,
  95. BSTR* ppwszHelpFile,
  96. DWORD* pdwHelpContext);
  97. // Callback on interface to release dynamic error memory
  98. STDMETHOD(ReleaseErrors) (const DWORD dwDynamicErrorId);
  99. private:
  100. // Refcouting
  101. LONG _cRefs;
  102. };
  103. //+-------------------------------------------------------------------------
  104. //
  105. // Class: CCIOleDBError
  106. //
  107. // Purpose: Posts OLE DB errors on behalf of CI
  108. //
  109. // History: 28-Apr-97 KrishnaN Created
  110. //
  111. //--------------------------------------------------------------------------
  112. class CCIOleDBError : public ISupportErrorInfo
  113. {
  114. public:
  115. CCIOleDBError( IUnknown & rUnknown, CMutexSem & mutex );
  116. ~CCIOleDBError();
  117. //
  118. // IUnknown methods.
  119. //
  120. STDMETHOD(QueryInterface) ( THIS_ REFIID riid, LPVOID *ppiuk );
  121. STDMETHOD_(ULONG, AddRef) (THIS);
  122. STDMETHOD_(ULONG, Release) (THIS);
  123. //
  124. // ISupportErrorInfo method
  125. //
  126. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  127. //
  128. // Supporting methods
  129. //
  130. inline void SetInterfaceArray(ULONG cErrInt, IID const * const * prgGuid)
  131. {
  132. _rgpErrInt = prgGuid;
  133. _cErrInt = cErrInt;
  134. };
  135. // Post an HRESULT to be looked up in ole-db sdk's
  136. // error collection or CI's error collection
  137. HRESULT PostHResult(HRESULT hrErr, const IID& refiid);
  138. HRESULT PostHResult(CException & e, const IID& refiid);
  139. // Post static strings and DISPPARAMs. Translates
  140. HRESULT PostParserError ( HRESULT hrErr,
  141. DWORD dwIds,
  142. DISPPARAMS **ppdispparams );
  143. // Post static strings and DISPPARAMs (does actual post)
  144. HRESULT PostError ( HRESULT hrErr,
  145. const IID & piid,
  146. DWORD dwIds,
  147. DISPPARAMS* pdispparams );
  148. // Clear Error Object
  149. inline static void ClearErrorInfo(void)
  150. {
  151. SetErrorInfo(0, NULL);
  152. };
  153. private:
  154. // Gets the error interfaces, IErrorInfo and IErrorRecords
  155. HRESULT GetErrorInterfaces(IErrorInfo** ppIErrorInfo,
  156. IErrorRecords** ppIErrorRecords);
  157. BOOL NeedToSetError ( SCODE scErr,
  158. IErrorInfo * pIErrorInfo,
  159. IErrorRecords *pErrorRecords);
  160. SCODE _GetErrorClassFact();
  161. CMutexSem & _mutex;
  162. IClassFactory * _pErrClassFact;
  163. IID const * const * _rgpErrInt; // Array of Interface IID Pointers
  164. ULONG _cErrInt; // Count of the IID Pointer array
  165. IUnknown & _rUnknown; // Controlling IUnknown
  166. };
  167. //+-------------------------------------------------------------------------
  168. //
  169. // Method: IsCIError, public
  170. //
  171. // Synopsis: Detects if the error is a CI error.
  172. //
  173. // Arguments: [hrError] - Error code in question.
  174. //
  175. // Returns: True if we detect to be a CI error.
  176. //
  177. // History: 29-Apr-97 KrishnaN Created
  178. //
  179. //--------------------------------------------------------------------------
  180. inline BOOL IsCIError(HRESULT hrError)
  181. {
  182. //
  183. // All CI errors, as listed in cierror.h, have FACILITY_ITF and
  184. // have codes in the range of 0x1600 to 0x18FF.
  185. //
  186. return (HRESULT_FACILITY(hrError) == FACILITY_ITF &&
  187. HRESULT_CODE(hrError) >= 0x1600 &&
  188. HRESULT_CODE(hrError) < 0x1850);
  189. }
  190. //+-------------------------------------------------------------------------
  191. //
  192. // Method: IsOleDBError, public
  193. //
  194. // Synopsis: Detects if the error is a OleDB error.
  195. //
  196. // Arguments: [hrError] - Error code in question.
  197. //
  198. // Returns: True if we detect to be a OleDB error.
  199. //
  200. // History: 29-Apr-97 KrishnaN Created
  201. //
  202. //--------------------------------------------------------------------------
  203. inline BOOL IsOleDBError(HRESULT hrError)
  204. {
  205. //
  206. // A HRESULT is a Ole DB error if it has the FACILITY_ITF facility and has
  207. // error codes in the range 0e00 to 0eff.
  208. //
  209. return (HRESULT_FACILITY(hrError) == FACILITY_ITF &&
  210. HRESULT_CODE(hrError) >= 0x0E00 &&
  211. HRESULT_CODE(hrError) < 0x0EFF);
  212. }
  213. //+-------------------------------------------------------------------------
  214. //
  215. // Method: IsParserError, public
  216. //
  217. // Synopsis: Detects if the error is a SQL Text Parser error.
  218. //
  219. // Arguments: [hrError] - Error code in question.
  220. //
  221. // Returns: True if we detect to be a OleDB error.
  222. //
  223. // History: 11-06-97 danleg Created
  224. //
  225. //--------------------------------------------------------------------------
  226. inline BOOL IsParserError(HRESULT hrError)
  227. {
  228. return (HRESULT_FACILITY(hrError) == FACILITY_ITF &&
  229. HRESULT_CODE(hrError) >= 0x092f &&
  230. HRESULT_CODE(hrError) < 0x0992);
  231. }