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.

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