
'-------------------
'NAMED SHARED MEMORY
'===================

'derived from:
'Creating Named Shared Memory
'http://msdn.microsoft.com/en-us/library/aa366551(VS.85).aspx

  '==============
  'CLIENT PROCESS
  '==============

  uses CoreWin 

  ' from winbase.h and winnt.h

  % PAGE_NOACCESS                0x01     
  % PAGE_READONLY                0x02     
  % PAGE_READWRITE               0x04     
  % PAGE_WRITECOPY               0x08     

  ' Token Specific Access Rights.

  % TOKEN_ASSIGN_PRIMARY         0x0001
  % TOKEN_DUPLICATE              0x0002
  % TOKEN_IMPERSONATE            0x0004
  % TOKEN_QUERY                  0x0008
  % TOKEN_QUERY_SOURCE           0x0010
  % TOKEN_ADJUST_PRIVILEGES      0x0020
  % TOKEN_ADJUST_GROUPS          0x0040
  % TOKEN_ADJUST_DEFAULT         0x0080
  % TOKEN_ADJUST_SESSIONID       0x0100

  % SECTION_QUERY                0x0001
  % SECTION_MAP_WRITE            0x0002
  % SECTION_MAP_READ             0x0004
  % SECTION_MAP_EXECUTE          0x0008
  % SECTION_EXTEND_SIZE          0x0010
  % SECTION_ALL_ACCESS           0x001F
  % SECTION_MAP_EXECUTE_EXPLICIT 0x0020
  % STANDARD_RIGHTS_REQUIRED     0x000F0000L
  % FILE_MAP_ALL_ACCESS  SECTION_ALL_ACCESS

  sys INVALID_HANDLE_VALUE = -1 'as ptr

  % TRUE  1
  % FALSE 0

  string Name="Local\MyFileMappingObject" 'GLOBAL\ NOT SUPPORTED
  % BUF_SIZE 256


  function main() as int
  ======================
  sys  hMapFile
  char *pBuf
  hMapFile = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, Name) 
  if hMapFile == 0
    print "Could not open file mapping object" + chr(13) + GetLastError()
    return 1
  endif
  @pBuf = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE)          
  if  @pBuf == 0
    print "Could not map view of file" + chr(13) + GetLastError() 
    CloseHandle(hMapFile)
    return 1
  endif
  print "CLIENT:  " pBuf
  UnmapViewOfFile(pBuf)
  CloseHandle(hMapFile)
  return 0
  end function

  main
