00001
00002 #include "WinSMTool.h"
00003 #include "WinTools.h"
00004
00005
00006 using namespace jbxwl;
00007
00008
00009 CWinSharedMemory::CWinSharedMemory(void)
00010 {
00011 CWinSharedMemory(JBXWL_DEFAULT_SMNAME, 1024, FALSE);
00012 }
00013
00014
00015
00016 CWinSharedMemory::CWinSharedMemory(const char* name, int size, BOOL create)
00017 {
00018 m_hMapping = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, mbs2ts((char*)name));
00019
00020 if (m_hMapping == NULL && create) {
00021
00022 m_hMapping = ::CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, mbs2ts((char*)name));
00023 }
00024
00025 if (m_hMapping != NULL) {
00026
00027 m_pMappingView = ::MapViewOfFile(m_hMapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
00028
00029
00030 m_pMutex = new CMutex(FALSE, mbs2ts((char*)name)+mbs2ts("_mutex"));
00031 }
00032 }
00033
00034
00035
00036 CWinSharedMemory::~CWinSharedMemory(void)
00037 {
00038 BOOL b = ::UnmapViewOfFile(m_pMappingView);
00039 ::CloseHandle(m_hMapping);
00040
00041 delete m_pMutex;
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 void CWinSharedMemory::get()
00055 {
00056
00057 m_pMutex->Lock(INFINITE);
00058
00059 m_pMutex->Unlock();
00060
00061
00062 }
00063
00064
00065
00066 void CWinSharedMemory::put()
00067 {
00068
00069
00070
00071 m_pMutex->Lock(INFINITE);
00072
00073 m_pMutex->Unlock();
00074 }
00075