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.

124 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. buildhive.h
  5. Abstract:
  6. Contains macros, type and function declarations
  7. used by buildhive.cpp
  8. Author:
  9. Mike Cirello
  10. Vijay Jayaseelan (vijayj)
  11. Revision History:
  12. 03 March 2001 :
  13. Rewamp the whole source to make it more maintainable
  14. (particularly readable)
  15. --*/
  16. #pragma once
  17. #include <windows.h>
  18. #include <setupapi.h>
  19. #include <stdio.h>
  20. #include <iostream>
  21. #include <list>
  22. #include <tchar.h>
  23. #include <string>
  24. #include <setupapi.hpp>
  25. //
  26. // Macros
  27. //
  28. #define ELEMENT_COUNT(x) (sizeof(x)/sizeof((x)[0]))
  29. //
  30. // forward declarations
  31. //
  32. class File;
  33. //
  34. // Types
  35. //
  36. typedef std::list<PCTSTR> StringList;
  37. typedef std::list<File*> FileList;
  38. typedef std::list<HINF> HandleList;
  39. //
  40. // constants
  41. //
  42. const DWORD errFILE_LOCKED = 10000001;
  43. const DWORD errBAD_FLAGS = 10000002;
  44. const DWORD errFILE_NOT_FOUND= 10000003;
  45. const DWORD errGENERAL_ERROR = 10000004;
  46. const DWORD errOUT_OF_MEMORY = 10000005;
  47. //
  48. // Prototypes
  49. //
  50. PCTSTR
  51. Error(
  52. VOID
  53. );
  54. BOOL
  55. SetPrivilege(
  56. IN HANDLE hToken,
  57. IN LPCTSTR PriviledgeName,
  58. IN BOOL Set);
  59. INT
  60. ShowProgramUsage(
  61. VOID
  62. );
  63. //
  64. // Exceptions
  65. //
  66. struct ProgramException : public std::exception {
  67. virtual void Dump(std::ostream &os) = 0;
  68. };
  69. //
  70. // Abstracts a Win32 error
  71. //
  72. struct W32Error : public ProgramException {
  73. DWORD ErrorCode;
  74. W32Error(DWORD ErrCode = GetLastError()) : ErrorCode(ErrCode){}
  75. void Dump(std::ostream &os) {
  76. WCHAR MsgBuffer[4096];
  77. MsgBuffer[0] = UNICODE_NULL;
  78. DWORD CharCount = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
  79. NULL,
  80. ErrorCode,
  81. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  82. MsgBuffer,
  83. sizeof(MsgBuffer)/sizeof(WCHAR),
  84. NULL);
  85. if (CharCount) {
  86. std::wstring Msg(MsgBuffer);
  87. os << Msg;
  88. } else {
  89. os << std::hex << ErrorCode;
  90. }
  91. }
  92. };