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

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


'==============
'SERVER PROCESS
'==============

  $filename "s.exe"
  'uses RTL64
  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 szName="Local\MyFileMappingObject"   'GLOBAL\ NOT SUPPOERTED
  string szMsg="This is a Message from the SERVER process."
  string cr=chr(13)+chr(10)
  % BUF_SIZE 0x1000

  ======================

  sys hMapFile
  sys pBuf
  hMapFile = CreateFileMapping(
  INVALID_HANDLE_VALUE,    ' use paging file
  NULL,                    ' default security 
  PAGE_READWRITE,          ' read/write access
  0,                       ' maximum object size (high-order DWORD) 
  BUF_SIZE,                ' maximum object size (low-order DWORD)  
  szName)                  ' name of mapping object
  if hMapFile == 0
    print "Could not create file mapping object" + cr + GetLastError()
    jmp fwd done
  endif
  ' 0x7 read/write permission
  pBuf = MapViewOfFile( hMapFile, 0x7, 0, 0, BUF_SIZE)          
  if pBuf == 0
    print "Could not map view of file" + cr + 
      GetLastError() 
    CloseHandle(hMapFile)
    jmp fwd done
  endif
  copy pBuf, strptr(szMsg), len(szMsg)
'
sys p=pbuf+0x400
bind p
  int i1,i2
  float f1,f2
end bind
i1=123
i2=456
f1=pi()


  print "SERVER:  " cr +
        szMsg cr +
        i1 " / " i2 ",  " f1 cr cr +
        "Press OK to terminate"
  UnmapViewOfFile(pBuf)
  CloseHandle(hMapFile)
  jmp fwd done
  '
  '
  =====
  done:
  =====


