home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / handler.cpp < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  106 lines

  1. /***
  2. *handler.cpp - defines C++ setHandler routine
  3. *
  4. *       Copyright (c) 1990-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Defines C++ setHandler routine.
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <stddef.h>
  12. #include <internal.h>
  13. #include <cruntime.h>
  14. #include <mtdll.h>
  15. #include <process.h>
  16. #include <new.h>
  17. #include <dbgint.h>
  18.  
  19.  
  20.  
  21. /* pointer to old-style C++ new handler */
  22. _PNH _pnhHeap;
  23.  
  24.  
  25. /***
  26. *_PNH _set_new_handler(_PNH pnh) - set the new handler
  27. *
  28. *Purpose:
  29. *       _set_new_handler is different from the ANSI C++ working standard definition
  30. *       of set_new_handler.  Therefore it has a leading underscore in its name.
  31. *
  32. *Entry:
  33. *       Pointer to the new handler to be installed.
  34. *
  35. *Return:
  36. *       Previous new handler
  37. *
  38. *******************************************************************************/
  39. _PNH __cdecl _set_new_handler(
  40.         _PNH pnh
  41.         )
  42. {
  43.         _PNH pnhOld;
  44.  
  45.         /* lock the heap */
  46.         _mlock(_HEAP_LOCK);
  47.  
  48.         pnhOld = _pnhHeap;
  49.         _pnhHeap = pnh;
  50.  
  51.         /* unlock the heap */
  52.         _munlock(_HEAP_LOCK);
  53.  
  54.         return(pnhOld);
  55. }
  56.  
  57.  
  58. /***
  59. *_PNH _query_new_handler(void) - query value of new handler
  60. *
  61. *Purpose:
  62. *       Obtain current new handler value.
  63. *
  64. *Entry:
  65. *       None
  66. *
  67. *       WARNING: This function is OBSOLETE. Use _query_new_ansi_handler instead.
  68. *
  69. *Return:
  70. *       Currently installed new handler
  71. *
  72. *******************************************************************************/
  73. _PNH __cdecl _query_new_handler (
  74.         void
  75.         )
  76. {
  77.         return _pnhHeap;
  78. }
  79.  
  80.  
  81. /***
  82. *int _callnewh - call the appropriate new handler
  83. *
  84. *Purpose:
  85. *       Call the appropriate new handler.
  86. *
  87. *Entry:
  88. *       None
  89. *
  90. *Return:
  91. *       1 for success
  92. *       0 for failure
  93. *       may throw bad_alloc
  94. *
  95. *******************************************************************************/
  96. extern "C" int __cdecl _callnewh(size_t size)
  97. {
  98.         {
  99.             _PNH pnh = _pnhHeap;
  100.  
  101.             if ( (pnh == NULL) || ((*pnh)(size) == 0) )
  102.                 return 0;
  103.         }
  104.         return 1;
  105. }
  106.