OxygenBasic 60

Started by James C. Fuller, May 16, 2023, 07:05:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

It is also possible with this technique, to share variables between different Processes. Even between 32bit and 64bit processes, using Named Shared Memory.

The trick is to bind the variables to shared memory instead of a static buffer. And to ensure 32/64bit compatibility, the variables within a bind block always align to 64bit boundaries.


Creating Named Shared Memory

http://msdn.microsoft.com/en-us/library/aa366551(VS.85).aspx


Theo Gottwald

#16
These are really advanced Features, Charles.
You can bind variables to shared Memory, that is AMAZING.
Can it be also done with Powerbasic currently?
If so, how?

The question i had was rather simple.
What I would need is something like

#INTOMAIN
GLOBAL GV as STRING
#ENDINTOMAIN

Which can be anywhere in an Include file and will then "as Text" merged into at the Start of the MAIN() Prozedure (PBMAIN() in Powerbasic).
This can be done "In Text-Replace", if you just automatically add a "##MAININCLUDES##" automatically as first stement in MAIN() and then after all replace it with all the collected #INTOMAIN-Blocks.

And the same with
#INTOGLOBAL
#ENDINTOGLOBAL
which will then be a GLOBAL Declaration, as if it was done before all Includes.
While theoretically any Declaration outside of a Procedure is global, Includes can also be included "Inside a scope" especially now, that you support functions-in-functions therefore a "#IntoGlobal" also makes sense. For Libraries. Technically this will be just treated as "Text Replacement" so its not hard to implement.



However that what you have is also very interesting. While i already use shared Memory for interprocess communication, i could not yet bind it to variables.

Charles Pegge

In PowerBasic you can use absolute arrays or pointer variables, and assign the mapped address (with offsets) of the shared space to them. But there isn't a construct like bind which would allow a whole block of individual variables to be dimensioned in a specified location.

With regard to distributing  blocks of global variables to different programs , I would generally use an inc file.

As an example I am going to use  an include file: GuiInterface.inc. This is useable on both 'gui servers' and 'gui clients'

  'GuiInterface.inc
  '20/05/2023
  '
  '  This file can be included in both client and
  '  server source code
  '
  '  USAGE:
  '
  '  SERVER ONLY:
  '  % GuiStateServer
  '  uses GuiInterface
  '
  '  CLIENT ONLY:
  '  % GuiDllName "MyGuiLib.dll" 'your server DLL
  '  uses GuiInterface
  '
  '
 
  #ifdef GuiStateServer
    '
    sys bu[0x400] 'STATIC BUFFER TO HOLD SHARED STATE VARIABLES
    '
    function guistate() as sys export
      return @bu
    end function
    #undef bu 'end bu scope
    '
  #else
    declare guistate lib GuiDllName () as sys
  #endif

  sys b = guistate()
  '
  bind b
    sys     hWndMain,hInst,inst,hDC,hRC
    int     pixelform
    int     mposx,mposy
    int     sposx,sposy
    int     eposx,eposy
    int     iposx,iposy
    int     mmove,bleft,bmid,bright,bwheel
    int     pause
    int     bkey,keyd,lastkey,lastchar
    int     running
    int     key[256]
  end bind

  #undef b 'end b scope