  'GuiInterface.inc
  '20/05/2023
  '15/05/2025
  '03/05/2026
  'CP
  '
  '  This file can be included in both client and
  '  server source code
  '
  '  USAGE:
  '  ======
  '
  '  SHARING INFO BETWEEN PROCESSES:
  '  % GuiSharedMem "Local\WinGuiState"
  '
  '  SERVER ONLY:
  '  % GuiStateServer
  '  % GuiSharedMem "Local\WinGuiState" 'USING NAMED SHARED MEMORY
  '  uses GuiInterface
  '
  '  CLIENT ONLY:
  '  % GuiStateClient
  '  % GuiDllName "MyGuiLib.dll" 'your server DLL
  '  uses GuiInterface

  '
  sys GuiMemHandle
  sys GuiMemBuffer
  '
  #ifdef GuiStateServer
    '
    #ifdef GuiSharedMem
      sys*bu
      ' PAGE_READWRITE 0x04
      ' case-sensitive name
      sys h=-1 '64bit pseudo handle    
      GuiMemHandle = CreateFileMapping(h,0,0x4,0,0x1000,GuiSharedMem)
      if GuiMemHandle == 0
        ers="Could not create file mapping object"
        ert=437
      else
        '0x7 read/write permission
        @bu = MapViewOfFile( GuiMemHandle, 0x7, 0, 0, 0x1000)          
        if @bu == 0
          ers="Could not map view of file" + cr + 
          ert=438 
        endif
      endif
      GuiMemBuffer=@bu
    #else 'NO SHARED MEM
      sys bu[0x1000] 'STATIC BUFFER TO HOLD SHARED STATE VARIABLES
    #endif
    '
    function guistate() as sys export 
      return @bu
    end function
    undef bu 'end bu scope
    '
  #else 'CLIENT
    '
    #ifdef GuiSharedMem
      sys*bu
      ' FILE_MAP_ALL_ACCESS 0x1f
      ' Case Sensitive Name
      GuiMemHandle = OpenFileMapping(0x1f,0,GuiSharedMem)
      if GuiMemHandle == 0
        ers="Could not open file mapping object"
        ert=439
      else
        '0x7 read/write permission
        @bu = MapViewOfFile( GuiMemHandle, 0x7, 0, 0, 0x1000)          
        if @bu == 0
          ers="Could not map view of file" + cr + 
          ert=440 
        endif
      endif
      function GuiState() as sys
        return @bu
      end function
      GuiMemBuffer=@bu
      undef bu 'end bu scope
    #else 'NO SHARED MEMORY, USING DLL CALL INSTEAD
      declare guistate lib GuiDllName () as sys
    #endif
    '
  #endif 'SERVER / CLIENT

  sys b = guistate()
  if ert
    print ers cr ert
  endif
 
  '
  bind b 
    sys     hWndMain,hInst,inst,hDC,hRC
    int     pixelform
    int     mposx,mposy
    int     sposx,sposy
    int     eposx,eposy
    int     mmove,bleft,bmid,bright,bwheel
    int     bkey,keyd,lastkey,lastchar
    int     pause,opening,closing,running,pausing
    int     act,actn
    int     pick, picking, picked
    int     pickchars,picktext, pickpix[4]
    int     key[0x100]
  end bind

  #undef b 'end b scope

  '#show int a=mposx '[rdi+48]

  
