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.

124 lines
3.2 KiB

  1. #ifndef __MS_UTIL_H__
  2. #define __MS_UTIL_H__
  3. extern "C"
  4. {
  5. #include "t120.h"
  6. }
  7. //
  8. // GUI message boxes kill us when we hit an assert or error, because they
  9. // have a message pump that causes messages to get dispatched, making it
  10. // very difficult for us to debug problems when they occur. Therefore
  11. // we redefine ERROR_OUT and ASSERT
  12. //
  13. #ifdef _DEBUG
  14. __inline void MyDebugBreak(void) { DebugBreak(); }
  15. #endif // _DEBUG
  16. /*
  17. * Macro used to force values to four byte boundaries. This macro will need to
  18. * be considered when portability issues arise.
  19. */
  20. #define ROUNDTOBOUNDARY(num) (((UINT)(num) + 0x03) & 0xfffffffcL)
  21. // the following create a dword that will look like "abcd" in debugger
  22. #ifdef SHIP_BUILD
  23. #define MAKE_STAMP_ID(a,b,c,d)
  24. #else
  25. #define MAKE_STAMP_ID(a,b,c,d) MAKELONG(MAKEWORD(a,b),MAKEWORD(c,d))
  26. #endif // SHIP_BUILD
  27. class CRefCount
  28. {
  29. public:
  30. #ifdef SHIP_BUILD
  31. CRefCount(void);
  32. #else
  33. CRefCount(DWORD dwStampID);
  34. #endif
  35. virtual ~CRefCount(void) = 0;
  36. LONG AddRef(void);
  37. LONG Release(void);
  38. void ReleaseNow(void);
  39. protected:
  40. LONG GetRefCount(void) { return m_cRefs; }
  41. BOOL IsRefCountZero(void) { return (0 == m_cRefs); }
  42. LONG Lock(void);
  43. LONG Unlock(BOOL fRelease = TRUE);
  44. LONG GetLockCount(void) { return m_cLocks; }
  45. BOOL IsLocked(void) { return (0 == m_cLocks); }
  46. private:
  47. #ifndef SHIP_BUILD
  48. DWORD m_dwStampID;// to remove before we ship it
  49. #endif
  50. LONG m_cRefs; // reference count
  51. LONG m_cLocks; // lock count of the essential contents
  52. };
  53. extern HINSTANCE g_hDllInst;
  54. __inline void My_CloseHandle(HANDLE hdl)
  55. {
  56. if (NULL != hdl)
  57. {
  58. CloseHandle(hdl);
  59. }
  60. }
  61. #if defined(_DEBUG)
  62. LPSTR _My_strdupA(LPCSTR pszSrc, LPSTR pszFileName, UINT nLineNumber);
  63. LPWSTR _My_strdupW(LPCWSTR pszSrc, LPSTR pszFileName, UINT nLineNumber);
  64. LPWSTR _My_strdupW2(UINT cchSrc, LPCWSTR pszSrc, LPSTR pszFileName, UINT nLineNumber);
  65. LPOSTR _My_strdupO2(LPBYTE lpbSrc, UINT cOctets, LPSTR pszFileName, UINT nLineNumber);
  66. #define My_strdupA(pszSrc) _My_strdupA(pszSrc, __FILE__, __LINE__)
  67. #define My_strdupW(pszSrc) _My_strdupW(pszSrc, __FILE__, __LINE__)
  68. #define My_strdupW2(cchSrc,pszSrc) _My_strdupW2(cchSrc, pszSrc, __FILE__, __LINE__)
  69. #define My_strdupO2(lpbSrc,cOctets) _My_strdupO2(lpbSrc, cOctets, __FILE__, __LINE__)
  70. #define My_strdupO(poszSrc) _My_strdupO2(poszSrc->value, poszSrc->length, __FILE__, __LINE__)
  71. #else
  72. LPSTR My_strdupA(LPCSTR pszSrc);
  73. LPWSTR My_strdupW(LPCWSTR pszSrc);
  74. LPWSTR My_strdupW2(UINT cchSrc, LPCWSTR pszSrc); // backward compatible to UnicodeString
  75. LPOSTR My_strdupO2(LPBYTE lpbSrc, UINT cOctets);
  76. __inline LPOSTR My_strdupO(LPOSTR poszSrc) { return My_strdupO2(poszSrc->value, poszSrc->length); }
  77. #endif
  78. UINT My_strlenA(LPCSTR pszSrc);
  79. UINT My_strlenW(LPCWSTR pszSrc);
  80. int My_strcmpW(LPCWSTR pwsz1, LPCWSTR pwsz2);
  81. #ifdef _UNICODE
  82. #define My_strdup My_strdupW
  83. #define My_strlen My_strlenW
  84. #define My_strcmp My_strcmpW
  85. #else
  86. #define My_strdup My_strdupA
  87. #define My_strlen My_strlenA
  88. #define My_strcmp lstrcmpA
  89. #endif
  90. INT My_strcmpO(LPOSTR posz1, LPOSTR posz2);
  91. #endif // __MS_UTIL_H__