Author Topic: Sharing global variables between different processes  (Read 955 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Sharing global variables between different processes
« on: September 29, 2019, 02:09:59 AM »
This is very similar to sharing variables with a DLL. However, the variable should not involve pointers, so flat char variables is the only useable type of string variable.

As of version 0.2.8  which has an alignment adjustment for globals, it is even possible to share a set of global variables between 32bit and 64bit processes.

Compile, execute and leave running first:
Code: [Select]
'shared memory between 32/64 bit processes
'http://msdn.microsoft.com/en-us/library/aa366551(VS.85).aspx
$filename "o.exe"
uses rtl64
uses corewin
sys hMapFile,pBuf
'configure for read/write 0x1000 mem space
hMapFile=CreateFileMapping(sys -1,0,4,0,0x1000,"OurVars01")
pBuf=MapViewOfFile(hMapFile,7,0,0,0x1000)
if pBuf
  bind pBuf {
    int a
    int b
    int c
    float f
    char s[0x100]
  }
  a=1
  b=2
  c=3
  f=1.5
  s="hello"
  print "Server ready (press 'OK' to close)"   
  UnmapViewOfFile(pBuf)
  CloseHandle(hMapFile)
endif

The client can then be run in jit mode (32bit)
Code: [Select]
uses corewin
sys hMapFile,pBuf
hMapFile = OpenFileMapping(7,0,"OurVars01")
if hMapFile
  pBuf = MapViewOfFile(hMapFile,7,0,0,0x1000)
  bind pBuf {
    int a
    int b
    int c
    float f
    char s[0x100]
  }
  string cr=chr(13,10)
  print a cr b cr c cr f cr s cr
  UnmapViewOfFile(pBuf)
  CloseHandle(hMapFile)
endif