Option _Explicit

Const BUF_SIZE = 256
Const INVALID_HANDLE_VALUE = -1
Const PAGE_READWRITE = &H04

Const FILE_MAP_ALL_ACCESS = &HF001F

Declare CustomType Library
    Function CreateFileMapping%& Alias "CreateFileMappingA" (ByVal hFile As _Offset, Byval lpFileMappingAttributes As _Offset, Byval flProtect As Long, Byval dwMaximumSizeHigh As _Unsigned Long, Byval dwMaximumSizeLow As _Unsigned Long, lpName As String)
    Function MapViewOfFile%& (ByVal hFileMappingObject As _Offset, Byval dwDesiredAccess As _Unsigned Long, Byval dwFileOffsetHigh As _Unsigned Long, Byval dwFileOffsetLow As _Unsigned Long, Byval dwNumberOfBytesToMap As _Offset)
    Sub UnmapViewOfFile (ByVal lpBaseAddress As _Offset)
    Function GetLastError~& ()
    Sub CloseHandle (ByVal hObject As _Offset)
End Declare

Declare Dynamic Library "kernel32"
    Sub CopyMemory Alias "RtlCopyMemory" (ByVal Destination As _Offset, Byval Source As _Offset, Byval Length As _Offset)
End Declare

Dim As String szName: szName = "MyFileMappingObject"
Dim As String szMsg: szMsg = "Message from first process."

Dim As _Offset hMapFile, pBuf

hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, BUF_SIZE, szName)

If hMapFile = 0 Then
    Print "Could not create file mapping object ("; GetLastError; ")."
    End
End If

pBuf = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE)

If pBuf = 0 Then
    Print "Could not map view of file ("; GetLastError; ")."
    CloseHandle hMapFile
    End
End If

CopyMemory pBuf, _Offset(szMsg), Len(szMsg)

Sleep
UnmapViewOfFile pBuf
CloseHandle hMapFile
