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.

67 lines
1.4 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /* BUFGLOB.CPP -- Implementation of GLOBAL_BUFFER class.
  6. *
  7. * History:
  8. * 03/22/93 gregj Created
  9. * 03/24/93 gregj Renamed from plain BUFFER, derived from BUFFER_BASE
  10. *
  11. */
  12. #include "npcommon.h"
  13. #include "buffer.h"
  14. BOOL GLOBAL_BUFFER::Alloc( UINT cbBuffer )
  15. {
  16. _hMem = ::GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, cbBuffer );
  17. if (_hMem == NULL) {
  18. _lpBuffer = NULL;
  19. _cb = 0;
  20. return FALSE;
  21. }
  22. _lpBuffer = ::GlobalLock( _hMem );
  23. _cb = cbBuffer;
  24. return TRUE;
  25. }
  26. BOOL GLOBAL_BUFFER::Realloc( UINT cbNew )
  27. {
  28. if (_hMem == NULL)
  29. return FALSE;
  30. ::GlobalUnlock( _hMem );
  31. HGLOBAL hNew = ::GlobalReAlloc( _hMem, cbNew, GMEM_MOVEABLE );
  32. if (hNew == NULL) {
  33. ::GlobalLock( _hMem );
  34. return FALSE;
  35. }
  36. _hMem = hNew;
  37. _lpBuffer = ::GlobalLock( _hMem );
  38. _cb = cbNew;
  39. return TRUE;
  40. }
  41. GLOBAL_BUFFER::GLOBAL_BUFFER( UINT cbInitial /* =0 */ )
  42. : BUFFER_BASE(),
  43. _hMem( NULL ),
  44. _lpBuffer( NULL )
  45. {
  46. if (cbInitial)
  47. Alloc( cbInitial );
  48. }
  49. GLOBAL_BUFFER::~GLOBAL_BUFFER()
  50. {
  51. if (_hMem != NULL) {
  52. ::GlobalUnlock( _hMem );
  53. ::GlobalFree( _hMem );
  54. _hMem = NULL;
  55. _lpBuffer = NULL;
  56. }
  57. }