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.

130 lines
3.3 KiB

  1. #ifndef __LASTERR_H__
  2. #define __LASTERR_H__
  3. ///////////////////////////////////////////////////////////
  4. //
  5. // lasterr.h - Class which supports the HH_GET_LAST_ERROR function.
  6. // - It supports a list of HR's indexed on idProcess.
  7. //
  8. //
  9. /********************************************************************
  10. How to set and error messages for HH_GET_LAST_ERROR.
  11. 1. Look in HHERROR.H for the currently defined errors.
  12. 2. Look in strtable.rc2 to see the string corresponding to this error.
  13. 3. Include the header lasterr.h in your file.
  14. 4. Use the following line to set an error:
  15. g_LastError.Set(idProcess, HH_E_FILENOTFOUND) ;
  16. 5. Note, you may have to modify your function to get the process id.
  17. 6. Follow the execution path to see if someone will overwrite your error.
  18. How to add a new error message for HH_GET_LAST_ERROR.
  19. 1. Add the ID for the error message to the header file HHERROR.H.
  20. 2. Use the naming convention HH_E_*, for example HH_E_FILENOTFOUND.
  21. 3. Add a define to strtable.h for this new error:
  22. #define IDS_HH_E_FILENOTFOUND 1301
  23. The name of the string is the name of the error with IDS_ prepended.
  24. Group it together with the other errors.
  25. 4. Add a string for this error to strtable.rc2.
  26. IDS_HH_E_FILENOTFOUND "The help file could not be found."
  27. 5. Modify the function ErrorStringId function in lasterr.h to translate
  28. your HRESULT into its STRINGID.
  29. *********************************************************************/
  30. // Possible error codes.
  31. #include "hherror.h"
  32. ///////////////////////////////////////////////////////////
  33. //
  34. // Forwards
  35. //
  36. class CProcessError ;
  37. class CLastError ;
  38. ///////////////////////////////////////////////////////////
  39. //
  40. // Global Functions
  41. //
  42. // Implementes the HH_GET_LAST_ERROR command.
  43. HRESULT hhGetLastError(HH_LAST_ERROR* dwData) ;
  44. // Returns a BSTR pointer given
  45. HRESULT GetStringFromHr(HRESULT hr, BSTR* pDescription);
  46. // returns the resource id for a HRESULT.
  47. int ErrorStringId(HRESULT hr);
  48. ///////////////////////////////////////////////////////////
  49. //
  50. // Externally Allocate members.
  51. //
  52. extern CLastError g_LastError ;
  53. ///////////////////////////////////////////////////////////
  54. //
  55. // Constants
  56. //
  57. // Grow the array by 10 elements each time.
  58. const int c_GrowBy = 5 ;
  59. ///////////////////////////////////////////////////////////
  60. //
  61. // CLastError
  62. //
  63. class CLastError
  64. {
  65. public:
  66. // Constructor
  67. CLastError() ;
  68. // Destructor
  69. ~CLastError() ;
  70. // Set the error
  71. void Set(HRESULT hr) ;
  72. // Get the error
  73. void Get(HRESULT* hr) ;
  74. // Reset the error
  75. void Reset() ; // Currently, this means that it defaults to E_FAIL.
  76. // Deletes all of the memory associated with the object.
  77. void Finish() ;
  78. //--- Internal helper functions.
  79. private:
  80. // Allocate the array.
  81. void AllocateArray() ;
  82. // Get error structure for the idProcess.
  83. CProcessError* FindProcess(DWORD idProcess) ;
  84. // Add New Process
  85. CProcessError* AddProcess();
  86. // Allocate Array
  87. CProcessError* AllocateArray(int elements) ;
  88. // Deallocate Array
  89. void DeallocateArray(CProcessError* p);
  90. //---Member variables
  91. private:
  92. // Holds the last error.
  93. CProcessError* m_ProcessErrorArray;
  94. // The number of allocated elements in the array.
  95. int m_maxindex ;
  96. // The last used index
  97. int m_lastindex ;
  98. };
  99. #endif //__LASTERR_H__