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.

133 lines
4.5 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 <tchar.h>
  21. #include <mmc.h>
  22. #ifndef STRINGS_ONLY
  23. #define IDM_BUTTON1 0x100
  24. #define IDM_BUTTON2 0x101
  25. extern HINSTANCE g_hinst;
  26. extern ULONG g_uObjects;
  27. #define OBJECT_CREATED InterlockedIncrement((long *)&g_uObjects);
  28. #define OBJECT_DESTROYED InterlockedDecrement((long *)&g_uObjects);
  29. // uncomment the following #define to enable message cracking
  30. // #define MMC_CRACK_MESSAGES
  31. void MMCN_Crack(BOOL bComponentData,
  32. IDataObject *pDataObject,
  33. IComponentData *pCompData,
  34. IComponent *pComp,
  35. MMC_NOTIFY_TYPE event,
  36. LPARAM arg,
  37. LPARAM param);
  38. #endif
  39. //=--------------------------------------------------------------------------=
  40. // allocates a temporary buffer that will disappear when it goes out of scope
  41. // NOTE: be careful of that -- make sure you use the string in the same or
  42. // nested scope in which you created this buffer. people should not use this
  43. // class directly. use the macro(s) below.
  44. //
  45. class TempBuffer {
  46. public:
  47. TempBuffer(ULONG cBytes) {
  48. m_pBuf = (cBytes <= 120) ? &m_szTmpBuf : HeapAlloc(GetProcessHeap(), 0, cBytes);
  49. m_fHeapAlloc = (cBytes > 120);
  50. }
  51. ~TempBuffer() {
  52. if (m_pBuf && m_fHeapAlloc) HeapFree(GetProcessHeap(), 0, m_pBuf);
  53. }
  54. void *GetBuffer() {
  55. return m_pBuf;
  56. }
  57. private:
  58. void *m_pBuf;
  59. // we'll use this temp buffer for small cases.
  60. //
  61. char m_szTmpBuf[120];
  62. unsigned m_fHeapAlloc:1;
  63. };
  64. //=--------------------------------------------------------------------------=
  65. // string helpers.
  66. //
  67. // given a _TCHAR, copy it into a wide buffer.
  68. // be careful about scoping when using this macro!
  69. //
  70. // how to use the below two macros:
  71. //
  72. // ...
  73. // LPTSTR pszT;
  74. // pszT = MyGetTStringRoutine();
  75. // MAKE_WIDEPTR_FROMSTR(pwsz, pszT);
  76. // MyUseWideStringRoutine(pwsz);
  77. // ...
  78. #ifdef UNICODE
  79. #define MAKE_WIDEPTR_FROMTSTR(ptrname, tstr) \
  80. long __l##ptrname = (lstrlenW(tstr) + 1) * sizeof(WCHAR); \
  81. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  82. lstrcpyW((LPWSTR)__TempBuffer##ptrname.GetBuffer(), tstr); \
  83. LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
  84. #else // ANSI
  85. #define MAKE_WIDEPTR_FROMTSTR(ptrname, tstr) \
  86. long __l##ptrname = (lstrlenA(tstr) + 1) * sizeof(WCHAR); \
  87. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  88. MultiByteToWideChar(CP_ACP, 0, tstr, -1, (LPWSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname); \
  89. LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
  90. #endif
  91. #ifdef UNICODE
  92. #define MAKE_WIDEPTR_FROMTSTR_ALLOC(ptrname, tstr) \
  93. long __l##ptrname = (lstrlenW(tstr) + 1) * sizeof(WCHAR); \
  94. LPWSTR ptrname = (LPWSTR)CoTaskMemAlloc(__l##ptrname); \
  95. lstrcpyW((LPWSTR)ptrname, tstr)
  96. #else // ANSI
  97. #define MAKE_WIDEPTR_FROMTSTR_ALLOC(ptrname, tstr) \
  98. long __l##ptrname = (lstrlenA(tstr) + 1) * sizeof(WCHAR); \
  99. LPWSTR ptrname = (LPWSTR)CoTaskMemAlloc(__l##ptrname); \
  100. MultiByteToWideChar(CP_ACP, 0, tstr, -1, ptrname, __l##ptrname)
  101. #endif
  102. //
  103. // similarily for MAKE_TSTRPTR_FROMWIDE. note that the first param does not
  104. // have to be declared, and no clean up must be done.
  105. //
  106. // * 2 for DBCS handling in below length computation
  107. //
  108. #ifdef UNICODE
  109. #define MAKE_TSTRPTR_FROMWIDE(ptrname, widestr) \
  110. long __l##ptrname = (wcslen(widestr) + 1) * 2 * sizeof(TCHAR); \
  111. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  112. lstrcpyW((LPTSTR)__TempBuffer##ptrname.GetBuffer(), widestr); \
  113. LPTSTR ptrname = (LPTSTR)__TempBuffer##ptrname.GetBuffer()
  114. #else // ANSI
  115. #define MAKE_TSTRPTR_FROMWIDE(ptrname, widestr) \
  116. long __l##ptrname = (wcslen(widestr) + 1) * 2 * sizeof(TCHAR); \
  117. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  118. WideCharToMultiByte(CP_ACP, 0, widestr, -1, (LPSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname, NULL, NULL); \
  119. LPTSTR ptrname = (LPTSTR)__TempBuffer##ptrname.GetBuffer()
  120. #endif
  121. #endif // _MMC_GLOBALS_H