SpoutSharedMemory.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. spoutSharedMemory.h
  3. Thanks and credit to Malcolm Bechard the author of this class
  4. https://github.com/mbechard
  5. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6. Copyright (c) 2014-2015, Lynn Jarvis. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. 1. Redistributions of source code must retain the above copyright notice,
  10. this list of conditions and the following disclaimer.
  11. 2. Redistributions in binary form must reproduce the above copyright notice,
  12. this list of conditions and the following disclaimer in the documentation
  13. and/or other materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  15. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  22. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #pragma once
  25. #ifndef __SpoutSharedMemory_ // standard way as well
  26. #define __SpoutSharedMemory_
  27. #include "SpoutCommon.h"
  28. #include <windowsx.h>
  29. #include <d3d9.h>
  30. #include <wingdi.h>
  31. enum SpoutCreateResult
  32. {
  33. SPOUT_CREATE_FAILED = 0,
  34. SPOUT_CREATE_SUCCESS,
  35. SPOUT_ALREADY_EXISTS,
  36. SPOUT_ALREADY_CREATED,
  37. };
  38. class SPOUT_DLLEXP SpoutSharedMemory {
  39. public:
  40. SpoutSharedMemory();
  41. ~SpoutSharedMemory();
  42. // Create a new memory segment, or attach to an existing one
  43. SpoutCreateResult Create(const char* name, int size);
  44. // Opens an existing one
  45. bool Open(const char* name);
  46. void Close();
  47. // Returns the buffer
  48. char* Lock();
  49. void Unlock();
  50. void Debug();
  51. private:
  52. char* m_pBuffer;
  53. HANDLE m_hMap;
  54. HANDLE m_hMutex;
  55. int m_lockCount;
  56. const char* m_pName;
  57. int m_size;
  58. };
  59. #endif