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.

167 lines
4.5 KiB

  1. // Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1993 Microsoft Corporation,
  3. // All rights reserved.
  4. // This source code is only intended as a supplement to the
  5. // Microsoft Foundation Classes Reference and Microsoft
  6. // QuickHelp and/or WinHelp documentation provided with the library.
  7. // See these sources for detailed information regarding the
  8. // Microsoft Foundation Classes product.
  9. /////////////////////////////////////////////////////////////////////////////
  10. // AFXDLLX.H: Extra header for building an MFC Extension DLL
  11. // This file is really a source file that you should include in the
  12. // main source file of your DLL.
  13. /////////////////////////////////////////////////////////////////////////////
  14. #ifdef _DEBUG
  15. #include <stdarg.h>
  16. extern "C" void CDECL
  17. AfxTrace(const char FAR* pszFormat, ...)
  18. {
  19. va_list args;
  20. va_start(args, pszFormat);
  21. (_AfxGetAppDebug()->lpfnTraceV)(pszFormat, args);
  22. }
  23. extern "C"
  24. void AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine)
  25. {
  26. (_AfxGetAppDebug()->lpfnAssertFailed)(lpszFileName, nLine);
  27. }
  28. #endif //_DEBUG
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Memory allocation is done by app !
  31. void* operator new(size_t nSize)
  32. {
  33. #ifdef _DEBUG
  34. ASSERT(_AfxGetAppData()->lpfnAppAlloc != NULL);
  35. ASSERT(_AfxGetAppDebug()->lpszAllocFileName == NULL);
  36. _AfxGetAppDebug()->bAllocObj = FALSE;
  37. #endif //_DEBUG
  38. void* p = (_AfxGetAppData()->lpfnAppAlloc)(nSize);
  39. if (p == NULL)
  40. AfxThrowMemoryException();
  41. return p;
  42. }
  43. #ifdef _DEBUG
  44. void* operator new(size_t nSize, LPCSTR lpszFileName, int nLine)
  45. {
  46. ASSERT(_AfxGetAppData()->lpfnAppAlloc != NULL);
  47. _AfxGetAppDebug()->lpszAllocFileName = lpszFileName;
  48. _AfxGetAppDebug()->nAllocLine = nLine;
  49. _AfxGetAppDebug()->bAllocObj = FALSE;
  50. void* p = (_AfxGetAppData()->lpfnAppAlloc)(nSize);
  51. _AfxGetAppDebug()->lpszAllocFileName = NULL;
  52. if (p == NULL)
  53. AfxThrowMemoryException();
  54. return p;
  55. }
  56. #endif //_DEBUG
  57. void operator delete(void* pbData)
  58. {
  59. if (pbData == NULL)
  60. return;
  61. #ifdef _DEBUG
  62. ASSERT(_AfxGetAppData()->lpfnAppFree != NULL);
  63. _AfxGetAppDebug()->bAllocObj = FALSE;
  64. #endif //_DEBUG
  65. (*_AfxGetAppData()->lpfnAppFree)(pbData);
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. // Additional CObject new/delete operators for memory tracking
  69. #ifdef _DEBUG
  70. void* CObject::operator new(size_t nSize)
  71. {
  72. ASSERT(_AfxGetAppData()->lpfnAppAlloc != NULL);
  73. ASSERT(_AfxGetAppDebug()->lpszAllocFileName == NULL);
  74. _AfxGetAppDebug()->bAllocObj = TRUE;
  75. void* p = (_AfxGetAppData()->lpfnAppAlloc)(nSize);
  76. if (p == NULL)
  77. AfxThrowMemoryException();
  78. return p;
  79. }
  80. void* CObject::operator new(size_t nSize, LPCSTR pFileName, int nLine)
  81. {
  82. ASSERT(_AfxGetAppData()->lpfnAppAlloc != NULL);
  83. _AfxGetAppDebug()->lpszAllocFileName = pFileName;
  84. _AfxGetAppDebug()->nAllocLine = nLine;
  85. _AfxGetAppDebug()->bAllocObj = TRUE;
  86. void* p = (_AfxGetAppData()->lpfnAppAlloc)(nSize);
  87. _AfxGetAppDebug()->lpszAllocFileName = NULL;
  88. if (p == NULL)
  89. AfxThrowMemoryException();
  90. return p;
  91. }
  92. void CObject::operator delete(void* pbData)
  93. {
  94. if (pbData == NULL)
  95. return;
  96. ASSERT(_AfxGetAppData()->lpfnAppFree != NULL);
  97. _AfxGetAppDebug()->bAllocObj = TRUE;
  98. (*_AfxGetAppData()->lpfnAppFree)(pbData);
  99. }
  100. #endif //_DEBUG
  101. /////////////////////////////////////////////////////////////////////////////
  102. // we must also replace any direct calls to malloc/free
  103. extern "C"
  104. void __far* __cdecl _fmalloc(size_t nSize)
  105. {
  106. #ifdef _DEBUG
  107. ASSERT(_AfxGetAppData()->lpfnAppAlloc != NULL);
  108. ASSERT(_AfxGetAppDebug()->lpszAllocFileName == NULL);
  109. _AfxGetAppDebug()->bAllocObj = FALSE;
  110. #endif //_DEBUG
  111. void* p = (_AfxGetAppData()->lpfnAppAlloc)(nSize);
  112. if (p == NULL)
  113. AfxThrowMemoryException();
  114. return p;
  115. }
  116. extern "C"
  117. void __cdecl _ffree(void __far* p)
  118. {
  119. #ifdef _DEBUG
  120. ASSERT(_AfxGetAppData()->lpfnAppFree != NULL);
  121. _AfxGetAppDebug()->bAllocObj = FALSE;
  122. #endif //_DEBUG
  123. (*_AfxGetAppData()->lpfnAppFree)(p);
  124. }
  125. extern "C"
  126. void __far* __cdecl _frealloc(void __far* pOld, size_t nSize)
  127. {
  128. #ifdef _DEBUG
  129. ASSERT(_AfxGetAppData()->lpfnAppReAlloc != NULL);
  130. _AfxGetAppDebug()->bAllocObj = FALSE;
  131. #endif //_DEBUG
  132. return (_AfxGetAppData()->lpfnAppReAlloc)(pOld, nSize);
  133. }
  134. /////////////////////////////////////////////////////////////////////////////
  135. // Also stub out the runtime init 'setenvp' routine to avoid malloc calls
  136. extern "C" void _cdecl _setenvp()
  137. {
  138. }
  139. /////////////////////////////////////////////////////////////////////////////