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.

829 lines
24 KiB

  1. /****************************************************************************
  2. Copyright information : Copyright (c) 1998-1999 Microsoft Corporation
  3. File Name : ErrorInfo.cpp
  4. Project Name : WMI Command Line
  5. Author Name : Ch. Sriramachandramurthy
  6. Date of Creation (dd/mm/yy) : 27th-September-2000
  7. Version Number : 1.0
  8. Brief Description : The CErrorInfo class provides the functionality
  9. for providing error information given the error
  10. object.
  11. Private : None
  12. Revision History :
  13. Last Modified by : Ch. Sriramachandramurthy
  14. Last Modified date : 16th-January-2001
  15. ****************************************************************************/
  16. // ErrorInfo.cpp : implementation file
  17. #include "Precomp.h"
  18. #include "ErrorInfo.h"
  19. /*------------------------------------------------------------------------
  20. Name :CErrorInfo
  21. Synopsis :This function initializes the member variables when
  22. an object of the class type is instantiated
  23. Type :Constructor
  24. Input parameter :None
  25. Output parameters :None
  26. Return Type :None
  27. Global Variables :None
  28. Calling Syntax :None
  29. Notes :None
  30. ------------------------------------------------------------------------*/
  31. CErrorInfo::CErrorInfo()
  32. {
  33. m_pIStatus = NULL;
  34. m_bWMIErrSrc = TRUE;
  35. m_pszErrStr = NULL;
  36. }
  37. /*------------------------------------------------------------------------
  38. Name :~CErrorInfo
  39. Synopsis :This function uninitializes the member variables
  40. when an object of the class type goes out of scope.
  41. Type :Destructor
  42. Input parameter :None
  43. Output parameters :None
  44. Return Type :None
  45. Global Variables :None
  46. Calling Syntax :None
  47. Notes :None
  48. ------------------------------------------------------------------------*/
  49. CErrorInfo::~CErrorInfo()
  50. {
  51. Uninitialize();
  52. }
  53. /*------------------------------------------------------------------------
  54. Name :Uninitialize
  55. Synopsis :This function uninitializes the member variables.
  56. Type :Member Function
  57. Input parameter :None
  58. Output parameters :None
  59. Return Type :void
  60. Global Variables :None
  61. Calling Syntax :Uninitialize()
  62. Notes :None
  63. ------------------------------------------------------------------------*/
  64. void CErrorInfo::Uninitialize()
  65. {
  66. SAFEIRELEASE(m_pIStatus);
  67. SAFEDELETE(m_pszErrStr);
  68. m_bWMIErrSrc = TRUE;
  69. }
  70. /*------------------------------------------------------------------------
  71. Name :GetErrorString
  72. Synopsis :This function takes the error code as input and returns
  73. an error string
  74. Type :Member Function
  75. Input parameter :
  76. hr - hresult value
  77. bTrace - trace flag
  78. Output parameters :None
  79. Return Type :_TCHAR*
  80. Global Variables :None
  81. Calling Syntax :GetErrorString(hr)
  82. Notes :None
  83. ------------------------------------------------------------------------*/
  84. void CErrorInfo::GetErrorString(HRESULT hr, BOOL bTrace, _bstr_t& bstrErrDesc,
  85. _bstr_t& bstrFacility)
  86. {
  87. try
  88. {
  89. // Get the text description of the error code
  90. GetWbemErrorText(hr, FALSE, bstrErrDesc, bstrFacility);
  91. // If the error source subsystem is 'Wbem' and the
  92. // TRACE is ON (get elaborated description from the
  93. // string table for the error code)
  94. if (m_bWMIErrSrc && bTrace)
  95. {
  96. m_pszErrStr = new _TCHAR[MAX_BUFFER];
  97. if (m_pszErrStr != NULL)
  98. {
  99. switch (hr)
  100. {
  101. case WBEM_NO_ERROR:
  102. LoadString(NULL, IDS_I_WBEM_NO_ERROR,
  103. m_pszErrStr, MAX_BUFFER);
  104. break;
  105. case WBEM_E_ACCESS_DENIED:
  106. LoadString(NULL, IDS_E_WBEM_E_ACCESS_DENIED,
  107. m_pszErrStr, MAX_BUFFER);
  108. break;
  109. case WBEM_E_ALREADY_EXISTS:
  110. LoadString(NULL, IDS_E_WBEM_E_ALREADY_EXISTS,
  111. m_pszErrStr, MAX_BUFFER);
  112. break;
  113. case WBEM_E_CANNOT_BE_KEY:
  114. LoadString(NULL, IDS_E_WBEM_E_CANNOT_BE_KEY,
  115. m_pszErrStr, MAX_BUFFER);
  116. break;
  117. case WBEM_E_CANNOT_BE_SINGLETON:
  118. LoadString(NULL, IDS_E_WBEM_E_CANNOT_BE_SINGLETON,
  119. m_pszErrStr, MAX_BUFFER);
  120. break;
  121. case WBEM_E_CLASS_HAS_CHILDREN:
  122. LoadString(NULL, IDS_E_WBEM_E_CLASS_HAS_CHILDREN,
  123. m_pszErrStr, MAX_BUFFER);
  124. break;
  125. case WBEM_E_CLASS_HAS_INSTANCES:
  126. LoadString(NULL, IDS_E_WBEM_E_CLASS_HAS_INSTANCES,
  127. m_pszErrStr, MAX_BUFFER);
  128. break;
  129. case WBEM_E_CRITICAL_ERROR:
  130. LoadString(NULL, IDS_E_WBEM_E_CRITICAL_ERROR,
  131. m_pszErrStr, MAX_BUFFER);
  132. break;
  133. case WBEM_E_FAILED:
  134. LoadString(NULL, IDS_E_WBEM_E_FAILED,
  135. m_pszErrStr, MAX_BUFFER);
  136. break;
  137. case WBEM_E_ILLEGAL_NULL:
  138. LoadString(NULL, IDS_E_WBEM_E_ILLEGAL_NULL,
  139. m_pszErrStr, MAX_BUFFER);
  140. break;
  141. case WBEM_E_ILLEGAL_OPERATION:
  142. LoadString(NULL, IDS_E_WBEM_E_ILLEGAL_OPERATION,
  143. m_pszErrStr, MAX_BUFFER);
  144. break;
  145. case WBEM_E_INCOMPLETE_CLASS:
  146. LoadString(NULL, IDS_E_WBEM_E_INCOMPLETE_CLASS,
  147. m_pszErrStr, MAX_BUFFER);
  148. break;
  149. case WBEM_E_INITIALIZATION_FAILURE:
  150. LoadString(NULL, IDS_E_WBEM_E_INITIALIZATION_FAILURE,
  151. m_pszErrStr, MAX_BUFFER);
  152. break;
  153. case WBEM_E_INVALID_CIM_TYPE:
  154. LoadString(NULL, IDS_E_WBEM_E_INVALID_CIM_TYPE,
  155. m_pszErrStr, MAX_BUFFER);
  156. break;
  157. case WBEM_E_INVALID_CLASS:
  158. LoadString(NULL, IDS_E_WBEM_E_INVALID_CLASS,
  159. m_pszErrStr, MAX_BUFFER);
  160. break;
  161. case WBEM_E_INVALID_CONTEXT:
  162. LoadString(NULL, IDS_E_WBEM_E_INVALID_CONTEXT,
  163. m_pszErrStr, MAX_BUFFER);
  164. break;
  165. case WBEM_E_INVALID_METHOD:
  166. LoadString(NULL, IDS_E_WBEM_E_INVALID_METHOD,
  167. m_pszErrStr, MAX_BUFFER);
  168. break;
  169. case WBEM_E_INVALID_METHOD_PARAMETERS:
  170. LoadString(NULL, IDS_E_WBEM_E_INVALID_METHOD_PARAMETERS,
  171. m_pszErrStr, MAX_BUFFER);
  172. break;
  173. case WBEM_E_INVALID_NAMESPACE:
  174. LoadString(NULL, IDS_E_WBEM_E_INVALID_NAMESPACE,
  175. m_pszErrStr, MAX_BUFFER);
  176. break;
  177. case WBEM_E_INVALID_OBJECT:
  178. LoadString(NULL, IDS_E_WBEM_E_INVALID_OBJECT,
  179. m_pszErrStr, MAX_BUFFER);
  180. break;
  181. case WBEM_E_INVALID_OPERATION:
  182. LoadString(NULL, IDS_E_WBEM_E_INVALID_OPERATION,
  183. m_pszErrStr, MAX_BUFFER);
  184. break;
  185. case WBEM_E_INVALID_PARAMETER:
  186. LoadString(NULL, IDS_E_WBEM_E_INVALID_PARAMETER,
  187. m_pszErrStr, MAX_BUFFER);
  188. break;
  189. case WBEM_E_INVALID_PROPERTY_TYPE:
  190. LoadString(NULL, IDS_E_WBEM_E_INVALID_PROPERTY_TYPE,
  191. m_pszErrStr, MAX_BUFFER);
  192. break;
  193. case WBEM_E_INVALID_PROVIDER_REGISTRATION:
  194. LoadString(NULL, IDS_E_WBEM_E_INVALID_PROVIDER_REGISTRATION,
  195. m_pszErrStr, MAX_BUFFER);
  196. break;
  197. case WBEM_E_INVALID_QUALIFIER_TYPE:
  198. LoadString(NULL, IDS_E_WBEM_E_INVALID_QUALIFIER_TYPE,
  199. m_pszErrStr, MAX_BUFFER);
  200. break;
  201. case WBEM_E_INVALID_QUERY:
  202. LoadString(NULL, IDS_E_WBEM_E_INVALID_QUERY,
  203. m_pszErrStr, MAX_BUFFER);
  204. break;
  205. case WBEM_E_INVALID_QUERY_TYPE:
  206. LoadString(NULL, IDS_E_WBEM_E_INVALID_QUERY_TYPE,
  207. m_pszErrStr, MAX_BUFFER);
  208. break;
  209. case WBEM_E_INVALID_STREAM:
  210. LoadString(NULL, IDS_E_WBEM_E_INVALID_STREAM,
  211. m_pszErrStr, MAX_BUFFER);
  212. break;
  213. case WBEM_E_INVALID_SUPERCLASS:
  214. LoadString(NULL, IDS_E_WBEM_E_INVALID_SUPERCLASS,
  215. m_pszErrStr, MAX_BUFFER);
  216. break;
  217. case WBEM_E_INVALID_SYNTAX:
  218. LoadString(NULL, IDS_E_WBEM_E_INVALID_SYNTAX,
  219. m_pszErrStr, MAX_BUFFER);
  220. break;
  221. case WBEM_E_NONDECORATED_OBJECT:
  222. LoadString(NULL, IDS_E_WBEM_E_NONDECORATED_OBJECT,
  223. m_pszErrStr, MAX_BUFFER);
  224. break;
  225. case WBEM_E_NOT_AVAILABLE:
  226. LoadString(NULL, IDS_E_WBEM_E_NOT_AVAILABLE,
  227. m_pszErrStr, MAX_BUFFER);
  228. break;
  229. case WBEM_E_NOT_FOUND:
  230. LoadString(NULL, IDS_E_WBEM_E_NOT_FOUND,
  231. m_pszErrStr, MAX_BUFFER);
  232. break;
  233. case WBEM_E_NOT_SUPPORTED:
  234. LoadString(NULL, IDS_E_WBEM_E_NOT_SUPPORTED,
  235. m_pszErrStr, MAX_BUFFER);
  236. break;
  237. case WBEM_E_OUT_OF_MEMORY:
  238. LoadString(NULL, IDS_E_WBEM_E_OUT_OF_MEMORY,
  239. m_pszErrStr, MAX_BUFFER);
  240. break;
  241. case WBEM_E_OVERRIDE_NOT_ALLOWED:
  242. LoadString(NULL, IDS_E_WBEM_E_OVERRIDE_NOT_ALLOWED,
  243. m_pszErrStr, MAX_BUFFER);
  244. break;
  245. case WBEM_E_PROPAGATED_PROPERTY:
  246. LoadString(NULL, IDS_E_WBEM_E_PROPAGATED_PROPERTY,
  247. m_pszErrStr, MAX_BUFFER);
  248. break;
  249. case WBEM_E_PROPAGATED_QUALIFIER:
  250. LoadString(NULL, IDS_E_WBEM_E_PROPAGATED_QUALIFIER,
  251. m_pszErrStr, MAX_BUFFER);
  252. break;
  253. case WBEM_E_PROVIDER_FAILURE:
  254. LoadString(NULL, IDS_E_WBEM_E_PROVIDER_FAILURE,
  255. m_pszErrStr, MAX_BUFFER);
  256. break;
  257. case WBEM_E_PROVIDER_LOAD_FAILURE:
  258. LoadString(NULL, IDS_E_WBEM_E_PROVIDER_LOAD_FAILURE,
  259. m_pszErrStr, MAX_BUFFER);
  260. break;
  261. case WBEM_E_PROVIDER_NOT_CAPABLE:
  262. LoadString(NULL, IDS_E_WBEM_E_PROVIDER_NOT_CAPABLE,
  263. m_pszErrStr, MAX_BUFFER);
  264. break;
  265. case WBEM_E_PROVIDER_NOT_FOUND:
  266. LoadString(NULL, IDS_E_WBEM_E_PROVIDER_NOT_FOUND,
  267. m_pszErrStr, MAX_BUFFER);
  268. break;
  269. case WBEM_E_QUERY_NOT_IMPLEMENTED:
  270. LoadString(NULL, IDS_E_WBEM_E_QUERY_NOT_IMPLEMENTED,
  271. m_pszErrStr, MAX_BUFFER);
  272. break;
  273. case WBEM_E_READ_ONLY:
  274. LoadString(NULL, IDS_E_WBEM_E_READ_ONLY,
  275. m_pszErrStr, MAX_BUFFER);
  276. break;
  277. case WBEM_E_TRANSPORT_FAILURE:
  278. LoadString(NULL, IDS_E_WBEM_E_TRANSPORT_FAILURE,
  279. m_pszErrStr, MAX_BUFFER);
  280. break;
  281. case WBEM_E_TYPE_MISMATCH:
  282. LoadString(NULL, IDS_E_WBEM_E_TYPE_MISMATCH,
  283. m_pszErrStr, MAX_BUFFER);
  284. break;
  285. case WBEM_E_UNEXPECTED:
  286. LoadString(NULL, IDS_E_WBEM_E_UNEXPECTED,
  287. m_pszErrStr, MAX_BUFFER);
  288. break;
  289. case WBEM_E_VALUE_OUT_OF_RANGE:
  290. LoadString(NULL, IDS_E_WBEM_E_VALUE_OUT_OF_RANGE,
  291. m_pszErrStr, MAX_BUFFER);
  292. break;
  293. case WBEM_S_ALREADY_EXISTS:
  294. LoadString(NULL, IDS_S_WBEM_S_ALREADY_EXISTS,
  295. m_pszErrStr, MAX_BUFFER);
  296. break;
  297. case WBEM_S_DIFFERENT:
  298. LoadString(NULL, IDS_S_WBEM_S_DIFFERENT,
  299. m_pszErrStr, MAX_BUFFER);
  300. break;
  301. case WBEM_S_FALSE:
  302. LoadString(NULL, IDS_S_WBEM_S_FALSE,
  303. m_pszErrStr, MAX_BUFFER);
  304. break;
  305. case WBEM_S_NO_MORE_DATA:
  306. LoadString(NULL, IDS_S_WBEM_S_NO_MORE_DATA,
  307. m_pszErrStr, MAX_BUFFER);
  308. break;
  309. case WBEM_S_PENDING:
  310. LoadString(NULL, IDS_S_WBEM_S_PENDING,
  311. m_pszErrStr, MAX_BUFFER);
  312. break;
  313. case WBEM_S_RESET_TO_DEFAULT:
  314. LoadString(NULL, IDS_S_WBEM_S_RESET_TO_DEFAULT,
  315. m_pszErrStr, MAX_BUFFER);
  316. break;
  317. case WBEM_S_TIMEDOUT:
  318. LoadString(NULL, IDS_S_WBEM_S_TIMEDOUT,
  319. m_pszErrStr, MAX_BUFFER);
  320. break;
  321. case WBEMESS_E_REGISTRATION_TOO_BROAD:
  322. LoadString(NULL, IDS_E_WBEMESS_E_REGISTRATION_TOO_BROAD,
  323. m_pszErrStr, MAX_BUFFER);
  324. break;
  325. case WBEMESS_E_REGISTRATION_TOO_PRECISE:
  326. LoadString(NULL, IDS_E_WBEMESS_E_REGISTRATION_TOO_PRECISE,
  327. m_pszErrStr, MAX_BUFFER);
  328. break;
  329. case WBEM_S_OPERATION_CANCELLED:
  330. LoadString(NULL, IDS_S_WBEM_S_OPERATION_CANCELLED,
  331. m_pszErrStr, MAX_BUFFER);
  332. break;
  333. case WBEM_S_DUPLICATE_OBJECTS:
  334. LoadString(NULL, IDS_S_WBEM_S_DUPLICATE_OBJECTS,
  335. m_pszErrStr, MAX_BUFFER);
  336. break;
  337. case WBEM_S_ACCESS_DENIED:
  338. LoadString(NULL, IDS_S_WBEM_S_ACCESS_DENIED,
  339. m_pszErrStr, MAX_BUFFER);
  340. break;
  341. case WBEM_S_PARTIAL_RESULTS:
  342. LoadString(NULL, IDS_S_WBEM_S_PARTIAL_RESULTS,
  343. m_pszErrStr, MAX_BUFFER);
  344. break;
  345. case WBEM_E_SYSTEM_PROPERTY:
  346. LoadString(NULL, IDS_E_WBEM_E_SYSTEM_PROPERTY,
  347. m_pszErrStr, MAX_BUFFER);
  348. break;
  349. case WBEM_E_INVALID_PROPERTY:
  350. LoadString(NULL, IDS_E_WBEM_E_INVALID_PROPERTY,
  351. m_pszErrStr, MAX_BUFFER);
  352. break;
  353. case WBEM_E_CALL_CANCELLED:
  354. LoadString(NULL, IDS_E_WBEM_E_CALL_CANCELLED,
  355. m_pszErrStr, MAX_BUFFER);
  356. break;
  357. case WBEM_E_SHUTTING_DOWN:
  358. LoadString(NULL, IDS_E_WBEM_E_SHUTTING_DOWN,
  359. m_pszErrStr, MAX_BUFFER);
  360. break;
  361. case WBEM_E_PROPAGATED_METHOD:
  362. LoadString(NULL, IDS_E_WBEM_E_PROPAGATED_METHOD,
  363. m_pszErrStr, MAX_BUFFER);
  364. break;
  365. case WBEM_E_UNSUPPORTED_PARAMETER:
  366. LoadString(NULL, IDS_E_WBEM_E_UNSUPPORTED_PARAMETER,
  367. m_pszErrStr, MAX_BUFFER);
  368. break;
  369. case WBEM_E_MISSING_PARAMETER_ID:
  370. LoadString(NULL, IDS_E_WBEM_E_MISSING_PARAMETER_ID,
  371. m_pszErrStr, MAX_BUFFER);
  372. break;
  373. case WBEM_E_INVALID_PARAMETER_ID:
  374. LoadString(NULL, IDS_E_WBEM_E_INVALID_PARAMETER_ID,
  375. m_pszErrStr, MAX_BUFFER);
  376. break;
  377. case WBEM_E_NONCONSECUTIVE_PARAMETER_IDS:
  378. LoadString(NULL, IDS_E_WBEM_E_NONCONSECUTIVE_PARAMETER_IDS,
  379. m_pszErrStr, MAX_BUFFER);
  380. break;
  381. case WBEM_E_PARAMETER_ID_ON_RETVAL:
  382. LoadString(NULL, IDS_E_WBEM_E_PARAMETER_ID_ON_RETVAL,
  383. m_pszErrStr, MAX_BUFFER);
  384. break;
  385. case WBEM_E_INVALID_OBJECT_PATH:
  386. LoadString(NULL, IDS_E_WBEM_E_INVALID_OBJECT_PATH,
  387. m_pszErrStr, MAX_BUFFER);
  388. break;
  389. case WBEM_E_OUT_OF_DISK_SPACE:
  390. LoadString(NULL, IDS_E_WBEM_E_OUT_OF_DISK_SPACE,
  391. m_pszErrStr, MAX_BUFFER);
  392. break;
  393. case WBEM_E_BUFFER_TOO_SMALL:
  394. LoadString(NULL, IDS_E_WBEM_E_BUFFER_TOO_SMALL,
  395. m_pszErrStr, MAX_BUFFER);
  396. break;
  397. case WBEM_E_UNSUPPORTED_PUT_EXTENSION:
  398. LoadString(NULL, IDS_E_WBEM_E_UNSUPPORTED_PUT_EXTENSION,
  399. m_pszErrStr, MAX_BUFFER);
  400. break;
  401. case WBEM_E_UNKNOWN_OBJECT_TYPE:
  402. LoadString(NULL, IDS_E_WBEM_E_UNKNOWN_OBJECT_TYPE,
  403. m_pszErrStr, MAX_BUFFER);
  404. break;
  405. case WBEM_E_UNKNOWN_PACKET_TYPE:
  406. LoadString(NULL, IDS_E_WBEM_E_UNKNOWN_PACKET_TYPE,
  407. m_pszErrStr, MAX_BUFFER);
  408. break;
  409. case WBEM_E_MARSHAL_VERSION_MISMATCH:
  410. LoadString(NULL, IDS_E_WBEM_E_MARSHAL_VERSION_MISMATCH,
  411. m_pszErrStr, MAX_BUFFER);
  412. break;
  413. case WBEM_E_MARSHAL_INVALID_SIGNATURE:
  414. LoadString(NULL, IDS_E_WBEM_E_MARSHAL_INVALID_SIGNATURE,
  415. m_pszErrStr, MAX_BUFFER);
  416. break;
  417. case WBEM_E_INVALID_QUALIFIER:
  418. LoadString(NULL, IDS_E_WBEM_E_INVALID_QUALIFIER,
  419. m_pszErrStr, MAX_BUFFER);
  420. break;
  421. case WBEM_E_INVALID_DUPLICATE_PARAMETER:
  422. LoadString(NULL, IDS_E_WBEM_E_INVALID_DUPLICATE_PARAMETER,
  423. m_pszErrStr, MAX_BUFFER);
  424. break;
  425. case WBEM_E_TOO_MUCH_DATA:
  426. LoadString(NULL, IDS_E_WBEM_E_TOO_MUCH_DATA,
  427. m_pszErrStr, MAX_BUFFER);
  428. break;
  429. case WBEM_E_SERVER_TOO_BUSY:
  430. LoadString(NULL, IDS_E_WBEM_E_SERVER_TOO_BUSY,
  431. m_pszErrStr, MAX_BUFFER);
  432. break;
  433. case WBEM_E_INVALID_FLAVOR:
  434. LoadString(NULL, IDS_E_WBEM_E_INVALID_FLAVOR,
  435. m_pszErrStr, MAX_BUFFER);
  436. break;
  437. case WBEM_E_CIRCULAR_REFERENCE:
  438. LoadString(NULL, IDS_E_WBEM_E_CIRCULAR_REFERENCE,
  439. m_pszErrStr, MAX_BUFFER);
  440. break;
  441. case WBEM_E_UNSUPPORTED_CLASS_UPDATE:
  442. LoadString(NULL, IDS_E_WBEM_E_UNSUPPORTED_CLASS_UPDATE,
  443. m_pszErrStr, MAX_BUFFER);
  444. break;
  445. case WBEM_E_CANNOT_CHANGE_KEY_INHERITANCE:
  446. LoadString(NULL, IDS_E_WBEM_E_CANNOT_CHANGE_KEY_INHERITANCE,
  447. m_pszErrStr, MAX_BUFFER);
  448. break;
  449. case WBEM_E_CANNOT_CHANGE_INDEX_INHERITANCE:
  450. LoadString(NULL, IDS_E_WBEM_E_CANNOT_CHANGE_INDEX_INHERITANCE,
  451. m_pszErrStr, MAX_BUFFER);
  452. break;
  453. case WBEM_E_TOO_MANY_PROPERTIES:
  454. LoadString(NULL, IDS_E_WBEM_E_TOO_MANY_PROPERTIES,
  455. m_pszErrStr, MAX_BUFFER);
  456. break;
  457. case WBEM_E_UPDATE_TYPE_MISMATCH:
  458. LoadString(NULL, IDS_E_WBEM_E_UPDATE_TYPE_MISMATCH,
  459. m_pszErrStr, MAX_BUFFER);
  460. break;
  461. case WBEM_E_UPDATE_OVERRIDE_NOT_ALLOWED:
  462. LoadString(NULL, IDS_E_WBEM_E_UPDATE_OVERRIDE_NOT_ALLOWED,
  463. m_pszErrStr, MAX_BUFFER);
  464. break;
  465. case WBEM_E_UPDATE_PROPAGATED_METHOD:
  466. LoadString(NULL, IDS_E_WBEM_E_UPDATE_PROPAGATED_METHOD,
  467. m_pszErrStr, MAX_BUFFER);
  468. break;
  469. case WBEM_E_METHOD_NOT_IMPLEMENTED:
  470. LoadString(NULL, IDS_E_WBEM_E_METHOD_NOT_IMPLEMENTED,
  471. m_pszErrStr, MAX_BUFFER);
  472. break;
  473. case WBEM_E_METHOD_DISABLED:
  474. LoadString(NULL, IDS_E_WBEM_E_METHOD_DISABLED,
  475. m_pszErrStr, MAX_BUFFER);
  476. break;
  477. case WBEM_E_REFRESHER_BUSY:
  478. LoadString(NULL, IDS_E_WBEM_E_REFRESHER_BUSY,
  479. m_pszErrStr, MAX_BUFFER);
  480. break;
  481. case WBEM_E_UNPARSABLE_QUERY:
  482. LoadString(NULL, IDS_E_WBEM_E_UNPARSABLE_QUERY,
  483. m_pszErrStr, MAX_BUFFER);
  484. break;
  485. case WBEM_E_NOT_EVENT_CLASS:
  486. LoadString(NULL, IDS_E_WBEM_E_NOT_EVENT_CLASS,
  487. m_pszErrStr, MAX_BUFFER);
  488. break;
  489. case WBEM_E_MISSING_GROUP_WITHIN:
  490. LoadString(NULL, WBEM_E_MISSING_GROUP_WITHIN,
  491. m_pszErrStr, MAX_BUFFER);
  492. break;
  493. case WBEM_E_MISSING_AGGREGATION_LIST:
  494. LoadString(NULL, IDS_E_WBEM_E_MISSING_AGGREGATION_LIST,
  495. m_pszErrStr, MAX_BUFFER);
  496. break;
  497. case WBEM_E_PROPERTY_NOT_AN_OBJECT:
  498. LoadString(NULL, IDS_E_WBEM_E_PROPERTY_NOT_AN_OBJECT,
  499. m_pszErrStr, MAX_BUFFER);
  500. break;
  501. case WBEM_E_AGGREGATING_BY_OBJECT:
  502. LoadString(NULL, IDS_E_WBEM_E_AGGREGATING_BY_OBJECT,
  503. m_pszErrStr, MAX_BUFFER);
  504. break;
  505. case WBEM_E_UNINTERPRETABLE_PROVIDER_QUERY:
  506. LoadString(NULL, IDS_E_WBEM_E_UNINTERPRETABLE_PROVIDER_QUERY,
  507. m_pszErrStr, MAX_BUFFER);
  508. break;
  509. case WBEM_E_BACKUP_RESTORE_WINMGMT_RUNNING:
  510. LoadString(NULL, IDS_E_WBEM_E_BACKUP_RESTORE_WINMGMT_RUNNING,
  511. m_pszErrStr, MAX_BUFFER);
  512. break;
  513. case WBEM_E_QUEUE_OVERFLOW:
  514. LoadString(NULL, IDS_E_WBEM_E_QUEUE_OVERFLOW,
  515. m_pszErrStr, MAX_BUFFER);
  516. break;
  517. case WBEM_E_PRIVILEGE_NOT_HELD:
  518. LoadString(NULL, IDS_E_WBEM_E_PRIVILEGE_NOT_HELD,
  519. m_pszErrStr, MAX_BUFFER);
  520. break;
  521. case WBEM_E_INVALID_OPERATOR:
  522. LoadString(NULL, IDS_E_WBEM_E_INVALID_OPERATOR,
  523. m_pszErrStr, MAX_BUFFER);
  524. break;
  525. case WBEM_E_LOCAL_CREDENTIALS:
  526. LoadString(NULL, IDS_E_WBEM_E_LOCAL_CREDENTIALS,
  527. m_pszErrStr, MAX_BUFFER);
  528. break;
  529. case WBEM_E_CANNOT_BE_ABSTRACT:
  530. LoadString(NULL, IDS_E_WBEM_E_CANNOT_BE_ABSTRACT,
  531. m_pszErrStr, MAX_BUFFER);
  532. break;
  533. case WBEM_E_AMENDED_OBJECT:
  534. LoadString(NULL, IDS_E_WBEM_E_AMENDED_OBJECT,
  535. m_pszErrStr, MAX_BUFFER);
  536. break;
  537. case WBEM_E_CLIENT_TOO_SLOW:
  538. LoadString(NULL, IDS_E_WBEM_E_CLIENT_TOO_SLOW,
  539. m_pszErrStr, MAX_BUFFER);
  540. break;
  541. default:
  542. LoadString(NULL, IDS_E_UNKNOWN_WBEM_ERROR,
  543. m_pszErrStr, MAX_BUFFER);
  544. break;
  545. }
  546. }
  547. else
  548. throw OUT_OF_MEMORY;
  549. bstrErrDesc = m_pszErrStr;
  550. SAFEDELETE(m_pszErrStr);
  551. }
  552. }
  553. catch(_com_error& e)
  554. {
  555. _com_issue_error(e.Error());
  556. }
  557. }
  558. /*------------------------------------------------------------------------
  559. Name :GetWbemErrorText
  560. Synopsis :This function takes the error code as input and returns
  561. an error string
  562. Type :Member Function
  563. Input parameter :
  564. hr - (error code) hresult value
  565. bXML - Flag to indicate whether error is required in XML form
  566. Output parameters :
  567. bstrError - String to containg error info in XML form
  568. Return Type :None
  569. Global Variables :None
  570. Calling Syntax :GetErrorString(hr)
  571. Notes :None
  572. ------------------------------------------------------------------------*/
  573. void CErrorInfo::GetWbemErrorText(HRESULT hr, BOOL bXML, _bstr_t& bstrError,
  574. _bstr_t& bstrFacilityCode)
  575. {
  576. try
  577. {
  578. CHString sTemp;
  579. if (bXML)
  580. {
  581. sTemp.Format(L"<HRESULT>0x%x</HRESULT>", hr);
  582. }
  583. bstrError += _bstr_t(sTemp);
  584. if (m_pIStatus == NULL)
  585. {
  586. if (SUCCEEDED(CreateStatusCodeObject()))
  587. {
  588. BSTR bstrErr = NULL, bstrFacility = NULL;
  589. // Get the text string description associated with
  590. // the error code.
  591. if(SUCCEEDED(m_pIStatus->GetErrorCodeText(hr, 0, 0, &bstrErr)))
  592. {
  593. if (bXML)
  594. {
  595. bstrError += L"<DESCRIPTION>";
  596. bstrError += bstrErr;
  597. bstrError += L"</DESCRIPTION>";
  598. }
  599. else
  600. {
  601. bstrError = bstrErr;
  602. }
  603. // Get the subsystem where the error occured
  604. if(SUCCEEDED(m_pIStatus->GetFacilityCodeText(hr, 0, 0,
  605. &bstrFacility)))
  606. {
  607. if (bstrFacility)
  608. {
  609. if (bXML)
  610. {
  611. bstrError += L"<FACILITYCODE>";
  612. bstrError += bstrFacility;
  613. bstrError += L"</FACILITYCODE>";
  614. }
  615. else
  616. {
  617. bstrFacilityCode = bstrFacility;
  618. }
  619. // If the subsystem is not Winmgmt ('Wbem')
  620. // i.e. anyone of the "Windows" | "SSIP" | "RPC" set
  621. // the m_bWMIErrSrc to FALSE
  622. if ((CompareTokens(_T("Wbem"), (_TCHAR*) bstrFacility)) ||
  623. (CompareTokens(_T("WMI"), (_TCHAR*) bstrFacility)))
  624. {
  625. m_bWMIErrSrc = TRUE;
  626. }
  627. else
  628. m_bWMIErrSrc = FALSE;
  629. }
  630. }
  631. SAFEBSTRFREE(bstrErr);
  632. SAFEBSTRFREE(bstrFacility);
  633. }
  634. else
  635. {
  636. if (bXML)
  637. {
  638. bstrError +=
  639. L"<DESCRIPTION>\"Unknown WBEM Error\"</DESCRIPTION>";
  640. bstrError += L"<FACILITYCODE/>";
  641. }
  642. m_bWMIErrSrc = FALSE;
  643. }
  644. SAFEIRELEASE(m_pIStatus);
  645. }
  646. }
  647. }
  648. catch(_com_error& e)
  649. {
  650. _com_issue_error(e.Error());
  651. }
  652. catch(CHeap_Exception)
  653. {
  654. _com_issue_error(WBEM_E_OUT_OF_MEMORY);
  655. }
  656. }
  657. /*------------------------------------------------------------------------
  658. Name :CreateStatusCodeObject()
  659. Synopsis :This function creates the single uninitialized
  660. object of the class associated with the CLSID
  661. CLSID_WbemStatusCodeText
  662. Type :Member Function
  663. Input parameter :None
  664. Output parameters :None
  665. Return Type :HRESULT
  666. Global Variables :None
  667. Calling Syntax :CreateStatusCodeObject()
  668. Notes :None
  669. -------------------------------------------------------------------*/
  670. HRESULT CErrorInfo::CreateStatusCodeObject()
  671. {
  672. // Create the single uninitialized object of the
  673. // class associated with the CLSID CLSID_WbemStatusCodeText
  674. return CoCreateInstance(CLSID_WbemStatusCodeText,
  675. 0, CLSCTX_INPROC_SERVER,
  676. IID_IWbemStatusCodeText,
  677. (LPVOID*) &m_pIStatus);
  678. }
  679. /*-------------------------------------------------------------------------
  680. Name :GetErrorFragment
  681. Synopsis :Frames the XML string for error info
  682. Type :Member Function
  683. Input parameters :
  684. hr - HResult Parameter
  685. Output parameters :
  686. bstrError - String to containg error info in XML form
  687. Return Type :void
  688. Global Variables :None
  689. Calling Syntax :GetErrorFragment()
  690. -------------------------------------------------------------------------*/
  691. void CErrorInfo::GetErrorFragment(HRESULT hr, _bstr_t& bstrError)
  692. {
  693. try
  694. {
  695. _bstr_t bstrFacility;
  696. bstrError = L"<ERROR>";
  697. GetWbemErrorText(hr, TRUE, bstrError, bstrFacility);
  698. bstrError += L"</ERROR>";
  699. }
  700. catch(_com_error& e)
  701. {
  702. _com_issue_error(e.Error());
  703. }
  704. }