Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
mapismem.cpp File Reference
#include <windows.h>
#include <windowsx.h>
#include "mapismem.h"
#include <memory.h>

Go to the source code of this file.

Defines

#define ZeroMemory(PTR, SIZE)   memset(PTR, 0, SIZE)

Functions

CSharedMemNSCreateSharedMemory (DWORD memSize, LPCTSTR memName, HANDLE *hSharedMemory)
CSharedMemNSOpenExistingSharedMemory (LPCTSTR memName, HANDLE *hSharedMemory)
void NSCloseSharedMemory (CSharedMem *pData, HANDLE hSharedMemory)

Define Documentation

#define ZeroMemory (   PTR,
  SIZE 
)    memset(PTR, 0, SIZE)

Definition at line 51 of file mapismem.cpp.


Function Documentation

void NSCloseSharedMemory ( CSharedMem pData,
HANDLE  hSharedMemory 
)

Definition at line 150 of file mapismem.cpp.

{
#ifdef WIN32
  if(pData != 0) 
  { 
    UnmapViewOfFile(pData); 
    pData = 0; 
  } 

  if(hSharedMemory != 0) 
  { 
    CloseHandle(hSharedMemory); 
    hSharedMemory = 0; 
  } 
#else

       if (pData != NULL)
       {
              GlobalFreePtr(pData);
              pData = NULL;
       }

#endif // WIN32
}

Here is the caller graph for this function:

CSharedMem* NSCreateSharedMemory ( DWORD  memSize,
LPCTSTR  memName,
HANDLE hSharedMemory 
)

Definition at line 63 of file mapismem.cpp.

{
#ifdef WIN32

  BOOL bExistedBefore;
  CSharedMem *pData;

  LPCTSTR szObjectName = memName; 
  DWORD dwSize = sizeof(CSharedMem) + memSize; 
  *hSharedMemory = CreateFileMapping( 
    (HANDLE)0xFFFFFFFF,0,PAGE_READWRITE,0,dwSize,szObjectName); 
  if(*hSharedMemory == 0) 
  { 
    return NULL; 
  } 
  bExistedBefore = (GetLastError() == ERROR_ALREADY_EXISTS); 
  if(bExistedBefore) 
  { 
       return NULL;
  } 

  pData = (CSharedMem *)MapViewOfFile( 
            *hSharedMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0); 
  if(pData == NULL) 
  { 
    return NULL; 
  } 

  ZeroMemory(pData, dwSize); 
  pData->m_dwSize = memSize; 

  return pData;
#else
  CSharedMem  *sMemChunk = NULL;
  DWORD dwSize = memSize = (sizeof(CSharedMem) + memSize); 

  if (sMemChunk != NULL)
         return(sMemChunk);

  sMemChunk = (CSharedMem *) GlobalAllocPtr(GMEM_MOVEABLE, dwSize);
  ZeroMemory(sMemChunk, (size_t) dwSize);
  sMemChunk->m_dwSize = dwSize;   // Missing in Communicator code!
  return(sMemChunk);

#endif // WIN32
}

Here is the caller graph for this function:

CSharedMem* NSOpenExistingSharedMemory ( LPCTSTR  memName,
HANDLE hSharedMemory 
)

Definition at line 116 of file mapismem.cpp.

{
#ifdef WIN32
  CSharedMem *pData;
  DWORD dwSize;

  LPCTSTR szObjectName = memName; 
  *hSharedMemory = OpenFileMapping( 
    FILE_MAP_WRITE,FALSE,szObjectName); 
  if(*hSharedMemory == 0) 
  { 
    return NULL; 
  } 

  pData = (CSharedMem *)MapViewOfFile( 
              *hSharedMemory,FILE_MAP_ALL_ACCESS,0,0,0); 
  if(pData == NULL) 
  { 
    return NULL; 
  } 
  
  dwSize = pData->m_dwSize; 
  return pData;
#else

  return(NULL);   // In Win16, this is really meaningless...

#endif
}  

Here is the caller graph for this function: