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.

112 lines
2.4 KiB

  1. #ifndef _DDBTN_COM_H_
  2. #define _DDBTN_COM_H_
  3. #ifdef UNDER_CE // not support GlobalAlloc
  4. #include "stub_ce.h" // Windows CE stub for unsupported APIs
  5. #endif // UNDER_CE
  6. #ifdef _DEBUG
  7. #include "dbg.h"
  8. static INT countAlloced;
  9. static INT countFreed;
  10. static INT curSize;
  11. inline VOID _printMemInfo(VOID)
  12. {
  13. Dbg(("countAlloced %d\n", countAlloced));
  14. Dbg(("countFreed %d\n", countFreed));
  15. Dbg(("curSize %d\n", curSize));
  16. }
  17. #define PrintMemInfo() _printMemInfo()
  18. #else
  19. #define PrintMemInfo()
  20. #endif
  21. inline VOID *MemAlloc(size_t size)
  22. {
  23. LPVOID p = GlobalAlloc(GMEM_FIXED, size);
  24. #ifdef _DEBUG
  25. if(p) {
  26. countAlloced++;
  27. curSize += (INT)GlobalSize(p);
  28. }
  29. #endif
  30. return p;
  31. }
  32. inline BOOL MemFree(LPVOID p)
  33. {
  34. #ifdef _DEBUG
  35. if(p) {
  36. countFreed++;
  37. curSize -= (INT)GlobalSize(p);
  38. }
  39. #endif
  40. BOOL ret = FALSE;
  41. if(p) {
  42. #ifdef _WIN64
  43. ret = (BOOL)(INT_PTR)GlobalFree(p);
  44. #else
  45. ret = (BOOL)GlobalFree(p);
  46. #endif
  47. }
  48. return ret;
  49. }
  50. //----------------------------------------------------------------
  51. inline LPWSTR StrdupW(LPWSTR lpwstr)
  52. {
  53. LPWSTR p;
  54. INT len;
  55. if(!lpwstr) {
  56. return NULL;
  57. }
  58. len = lstrlenW(lpwstr);
  59. p = (LPWSTR)MemAlloc((len + 1)* sizeof(WCHAR) );
  60. if(p) {
  61. CopyMemory(p, lpwstr, len * sizeof(WCHAR));
  62. p[len] = (WCHAR)0x0000;
  63. }
  64. return p;
  65. }
  66. class CCommon {
  67. public:
  68. void *operator new(size_t size) {
  69. BYTE *p = (BYTE *)MemAlloc(size);
  70. if(p) {
  71. ZeroMemory(p, size);
  72. }
  73. return (void *)p;
  74. }
  75. void operator delete(void *pv) {
  76. if(pv) {
  77. MemFree(pv);
  78. }
  79. }
  80. };
  81. //----------------------------------------------------------------
  82. #define UnrefForMsg() UNREFERENCED_PARAMETER(hwnd);\
  83. UNREFERENCED_PARAMETER(wParam);\
  84. UNREFERENCED_PARAMETER(lParam)
  85. #define UnrefForCmd() UNREFERENCED_PARAMETER(hwnd);\
  86. UNREFERENCED_PARAMETER(wCommand);\
  87. UNREFERENCED_PARAMETER(wNotify);\
  88. UNREFERENCED_PARAMETER(hwndCtrl)
  89. #define Unref(a) UNREFERENCED_PARAMETER(a)
  90. #define Unref1(a) UNREFERENCED_PARAMETER(a)
  91. #define Unref2(a, b) UNREFERENCED_PARAMETER(a);\
  92. UNREFERENCED_PARAMETER(b)
  93. #define Unref3(a,b,c) UNREFERENCED_PARAMETER(a);\
  94. UNREFERENCED_PARAMETER(b);\
  95. UNREFERENCED_PARAMETER(c)
  96. #define Unref4(a,b,c,d) UNREFERENCED_PARAMETER(a);\
  97. UNREFERENCED_PARAMETER(b);\
  98. UNREFERENCED_PARAMETER(c);\
  99. UNREFERENCED_PARAMETER(d)
  100. #endif //_DDBTN_COM_H_