home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / INCLUDE / AFXDLLX.H_ / AFXDLLX.H
Encoding:
C/C++ Source or Header  |  1993-02-08  |  4.3 KB  |  160 lines

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