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.

122 lines
2.6 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. Dbg(("Alloc: %4d byte\n", GlobalSize(p)));
  29. }
  30. #endif
  31. return p;
  32. }
  33. inline BOOL MemFree(LPVOID p)
  34. {
  35. #ifdef _DEBUG
  36. if(p) {
  37. countFreed++;
  38. curSize -= (INT)GlobalSize(p);
  39. Dbg(("Free : %4d byte\n", GlobalSize(p)));
  40. }
  41. #endif
  42. BOOL ret = FALSE;
  43. if(p) {
  44. LPVOID lpRet = (LPVOID)GlobalFree(p);
  45. if(NULL == lpRet) {
  46. ret = TRUE;
  47. }
  48. }
  49. return ret;
  50. }
  51. //----------------------------------------------------------------
  52. inline LPWSTR StrdupW(LPWSTR lpwstr)
  53. {
  54. LPWSTR p;
  55. INT len;
  56. if(!lpwstr) {
  57. return NULL;
  58. }
  59. len = lstrlenW(lpwstr);
  60. p = (LPWSTR)MemAlloc((len + 1)* sizeof(WCHAR) );
  61. if(p) {
  62. CopyMemory(p, lpwstr, len * sizeof(WCHAR));
  63. p[len] = (WCHAR)0x0000;
  64. }
  65. return p;
  66. }
  67. class CCommon {
  68. public:
  69. void *operator new(size_t size) {
  70. BYTE *p = (BYTE *)MemAlloc(size);
  71. if(p) {
  72. ZeroMemory(p, size);
  73. }
  74. return (void *)p;
  75. }
  76. void operator delete(void *pv) {
  77. if(pv) {
  78. MemFree(pv);
  79. }
  80. }
  81. };
  82. // to reference each other
  83. class CDDButton;
  84. typedef CDDButton *LPCDDButton;
  85. class CDDBItem;
  86. typedef CDDBItem *LPCDDBItem;
  87. //----------------------------------------------------------------
  88. #define UnrefForMsg() UNREFERENCED_PARAMETER(hwnd);\
  89. UNREFERENCED_PARAMETER(wParam);\
  90. UNREFERENCED_PARAMETER(lParam)
  91. #define UnrefForCmd() UNREFERENCED_PARAMETER(hwnd);\
  92. UNREFERENCED_PARAMETER(wCommand);\
  93. UNREFERENCED_PARAMETER(wNotify);\
  94. UNREFERENCED_PARAMETER(hwndCtrl)
  95. #define Unref(a) UNREFERENCED_PARAMETER(a)
  96. #define Unref1(a) UNREFERENCED_PARAMETER(a)
  97. #define Unref2(a, b) UNREFERENCED_PARAMETER(a);\
  98. UNREFERENCED_PARAMETER(b)
  99. #define Unref3(a,b,c) UNREFERENCED_PARAMETER(a);\
  100. UNREFERENCED_PARAMETER(b);\
  101. UNREFERENCED_PARAMETER(c)
  102. #define Unref4(a,b,c,d) UNREFERENCED_PARAMETER(a);\
  103. UNREFERENCED_PARAMETER(b);\
  104. UNREFERENCED_PARAMETER(c);\
  105. UNREFERENCED_PARAMETER(d)
  106. #endif //_DDBTN_COM_H_