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.

137 lines
5.0 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. //
  6. //
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  9. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  10. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  11. // PURPOSE.
  12. //
  13. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  14. //
  15. //
  16. //
  17. //==============================================================;
  18. #ifndef _MMC_GLOBALS_H
  19. #define _MMC_GLOBALS_H
  20. #include <mmc.h>
  21. #include <tchar.h>
  22. #ifndef STRINGS_ONLY
  23. enum UPDATE_VIEWS_HINT {UPDATE_SCOPEITEM = 1000, DELETE_SCOPEITEM, UPDATE_RESULTITEM, DELETE_RESULTITEM};
  24. enum ITEM_TYPE {SCOPE = 10, RESULT};
  25. #define IDM_BUTTON1 0x100
  26. #define IDM_BUTTON2 0x101
  27. extern HINSTANCE g_hinst;
  28. extern ULONG g_uObjects;
  29. #define OBJECT_CREATED InterlockedIncrement((long *)&g_uObjects);
  30. #define OBJECT_DESTROYED InterlockedDecrement((long *)&g_uObjects);
  31. // uncomment the following #define to enable message cracking
  32. // #define MMC_CRACK_MESSAGES
  33. void MMCN_Crack(BOOL bComponentData,
  34. IDataObject *pDataObject,
  35. IComponentData *pCompData,
  36. IComponent *pComp,
  37. MMC_NOTIFY_TYPE event,
  38. LPARAM arg,
  39. LPARAM param);
  40. #endif
  41. //=--------------------------------------------------------------------------=
  42. // allocates a temporary buffer that will disappear when it goes out of scope
  43. // NOTE: be careful of that -- make sure you use the string in the same or
  44. // nested scope in which you created this buffer. people should not use this
  45. // class directly. use the macro(s) below.
  46. //
  47. class TempBuffer {
  48. public:
  49. TempBuffer(ULONG cBytes) {
  50. m_pBuf = (cBytes <= 120) ? &m_szTmpBuf : HeapAlloc(GetProcessHeap(), 0, cBytes);
  51. m_fHeapAlloc = (cBytes > 120);
  52. }
  53. ~TempBuffer() {
  54. if (m_pBuf && m_fHeapAlloc) HeapFree(GetProcessHeap(), 0, m_pBuf);
  55. }
  56. void *GetBuffer() {
  57. return m_pBuf;
  58. }
  59. private:
  60. void *m_pBuf;
  61. // we'll use this temp buffer for small cases.
  62. //
  63. char m_szTmpBuf[120];
  64. unsigned m_fHeapAlloc:1;
  65. };
  66. //=--------------------------------------------------------------------------=
  67. // string helpers.
  68. //
  69. // given a _TCHAR, copy it into a wide buffer.
  70. // be careful about scoping when using this macro!
  71. //
  72. // how to use the below two macros:
  73. //
  74. // ...
  75. // LPTSTR pszT;
  76. // pszT = MyGetTStringRoutine();
  77. // MAKE_WIDEPTR_FROMSTR(pwsz, pszT);
  78. // MyUseWideStringRoutine(pwsz);
  79. // ...
  80. #ifdef UNICODE
  81. #define MAKE_WIDEPTR_FROMTSTR(ptrname, tstr) \
  82. long __l##ptrname = (lstrlenW(tstr) + 1) * sizeof(WCHAR); \
  83. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  84. lstrcpyW((LPWSTR)__TempBuffer##ptrname.GetBuffer(), tstr); \
  85. LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
  86. #else // ANSI
  87. #define MAKE_WIDEPTR_FROMTSTR(ptrname, tstr) \
  88. long __l##ptrname = (lstrlenA(tstr) + 1) * sizeof(WCHAR); \
  89. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  90. MultiByteToWideChar(CP_ACP, 0, tstr, -1, (LPWSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname); \
  91. LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
  92. #endif
  93. #ifdef UNICODE
  94. #define MAKE_WIDEPTR_FROMTSTR_ALLOC(ptrname, tstr) \
  95. long __l##ptrname = (lstrlenW(tstr) + 1) * sizeof(WCHAR); \
  96. LPWSTR ptrname = (LPWSTR)CoTaskMemAlloc(__l##ptrname); \
  97. lstrcpyW((LPWSTR)ptrname, tstr)
  98. #else // ANSI
  99. #define MAKE_WIDEPTR_FROMTSTR_ALLOC(ptrname, tstr) \
  100. long __l##ptrname = (lstrlenA(tstr) + 1) * sizeof(WCHAR); \
  101. LPWSTR ptrname = (LPWSTR)CoTaskMemAlloc(__l##ptrname); \
  102. MultiByteToWideChar(CP_ACP, 0, tstr, -1, ptrname, __l##ptrname)
  103. #endif
  104. //
  105. // similarily for MAKE_TSTRPTR_FROMWIDE. note that the first param does not
  106. // have to be declared, and no clean up must be done.
  107. //
  108. // * 2 for DBCS handling in below length computation
  109. //
  110. #ifdef UNICODE
  111. #define MAKE_TSTRPTR_FROMWIDE(ptrname, widestr) \
  112. long __l##ptrname = (wcslen(widestr) + 1) * 2 * sizeof(TCHAR); \
  113. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  114. lstrcpyW((LPTSTR)__TempBuffer##ptrname.GetBuffer(), widestr); \
  115. LPTSTR ptrname = (LPTSTR)__TempBuffer##ptrname.GetBuffer()
  116. #else // ANSI
  117. #define MAKE_TSTRPTR_FROMWIDE(ptrname, widestr) \
  118. long __l##ptrname = (wcslen(widestr) + 1) * 2 * sizeof(TCHAR); \
  119. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  120. WideCharToMultiByte(CP_ACP, 0, widestr, -1, (LPSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname, NULL, NULL); \
  121. LPTSTR ptrname = (LPTSTR)__TempBuffer##ptrname.GetBuffer()
  122. #endif
  123. #endif // _MMC_GLOBALS_H