ShareMemory_IF.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // ShareMemory_IF.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include <string>
  5. #include "ShareMemory_IF.h"
  6. using namespace std;
  7. CShareMemory_Circle *g_pBigSm = NULL;
  8. CShareMemory_Circle *g_pSmallSm = NULL;
  9. string g_Sharemem_if_BigName = "CirSMIFBig";
  10. string g_Sharemem_if_SmallName = "CirSMIFSm";
  11. SHAREMEMORY_IF_C_API int Init_Circle_SM_IF(DWORD &BigBlockSize, DWORD &BigBlockCount, DWORD &SmallBlockSize, DWORD &SmallBlockCount)
  12. {
  13. int ret = -1;
  14. if (g_pBigSm == NULL)
  15. {
  16. g_pBigSm = new CShareMemory_Circle();
  17. }
  18. if (g_pSmallSm == NULL)
  19. {
  20. g_pSmallSm = new CShareMemory_Circle();
  21. }
  22. if (g_pBigSm->Create(g_Sharemem_if_BigName.c_str(), BigBlockSize, BigBlockCount, SM_READWRITE) >= 0)
  23. {
  24. g_pBigSm->Close();
  25. ret = g_pSmallSm->Create(g_Sharemem_if_SmallName.c_str(), SmallBlockSize, SmallBlockCount, SM_READWRITE);
  26. g_pSmallSm->Close();
  27. }
  28. //return 0;
  29. return ret;
  30. }
  31. SHAREMEMORY_IF_C_API const char* Get_Circle_SM_Object(DWORD BlockSize)
  32. {
  33. if (g_pSmallSm->GetSize() >= BlockSize)
  34. {
  35. return g_Sharemem_if_SmallName.c_str();
  36. }
  37. else if (g_pBigSm->GetSize() >= BlockSize)
  38. {
  39. return g_Sharemem_if_BigName.c_str();
  40. }
  41. return NULL;
  42. }
  43. SHAREMEMORY_IF_C_API void Exit_Circle_SM_IF()
  44. {
  45. delete g_pBigSm;
  46. g_pBigSm = NULL;
  47. delete g_pSmallSm;
  48. g_pSmallSm = NULL;
  49. }