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.

101 lines
2.1 KiB

  1. // Copyright (c) Microsoft. All rights reserved.
  2. //
  3. // This is unpublished source code of Microsoft.
  4. // The copyright notice above does not evidence any
  5. // actual or intended publication of such source code.
  6. // OneLiner : Implementation of MWmiError
  7. // DevUnit : wlbstest
  8. // Author : Murtaza Hakim
  9. // include files
  10. #include "MWmiError.h"
  11. #include "MTrace.h"
  12. // initialize static variables.
  13. //
  14. MWmiError* MWmiError::_instance = 0;
  15. // constructor
  16. //
  17. MWmiError::MWmiError()
  18. : pStatus(NULL)
  19. {
  20. SCODE sc;
  21. sc = CoCreateInstance(CLSID_WbemStatusCodeText, 0, CLSCTX_INPROC_SERVER,
  22. IID_IWbemStatusCodeText, (LPVOID *) &pStatus);
  23. if( sc != S_OK )
  24. {
  25. TRACE(MTrace::SEVERE_ERROR, L"CoCreateInstance failure\n");
  26. throw( WBEM_E_UNEXPECTED );
  27. }
  28. }
  29. // Instance
  30. //
  31. MWmiError*
  32. MWmiError::Instance()
  33. {
  34. if( _instance == 0 )
  35. {
  36. _instance = new MWmiError;
  37. }
  38. return _instance;
  39. }
  40. // GetErrorCodeText
  41. //
  42. MWmiError::MWmiError_Error
  43. MWmiError::GetErrorCodeText( const HRESULT hr,
  44. _bstr_t& errText )
  45. {
  46. MWmiError_Error err;
  47. SCODE sc;
  48. BSTR bstr = 0;
  49. sc = pStatus->GetFacilityCodeText( hr,
  50. 0,
  51. 0,
  52. &bstr );
  53. if( sc != S_OK )
  54. {
  55. TRACE(MTrace::SEVERE_ERROR, L"CoCreateInstance failure\n");
  56. throw( WBEM_E_UNEXPECTED );
  57. }
  58. errText = bstr;
  59. SysFreeString( bstr );
  60. bstr = 0;
  61. sc = pStatus->GetErrorCodeText( hr,
  62. 0,
  63. 0,
  64. &bstr );
  65. if( sc != S_OK )
  66. {
  67. TRACE(MTrace::SEVERE_ERROR, L"CoCreateInstance failure\n");
  68. throw( WBEM_E_UNEXPECTED );
  69. }
  70. errText = errText + L": " + bstr;
  71. SysFreeString( bstr );
  72. bstr = 0;
  73. return MWmiError_SUCCESS;
  74. }
  75. // GetErrorCodeText
  76. //
  77. MWmiError::MWmiError_Error
  78. GetErrorCodeText( const HRESULT hr, _bstr_t& errText )
  79. {
  80. static MWmiError* wmiErr = MWmiError::Instance();
  81. return wmiErr->GetErrorCodeText( hr, errText );
  82. }