I've been investigating since many days about how to share easily data between running exe (not using files). What I have found so far is the possibility to use a shared dll segment.
¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
¨¨¨¨¨¨¨¨¨¨:¨Prog_a(1)¨:¨¨¨¨¨¨:¨Prog_a(2)¨:¨¨¨¨¨¨¨¨
¨¨¨¨¨¨¨¨¨¨¨¨¨¨/¨\¨¨¨¨¨¨¨¨¨¨¨¨¨¨/¨¨\¨¨¨¨¨¨¨¨¨¨¨¨
¨¨¨¨¨¨¨¨¨¨¨¨¨/¨¨¨\¨¨¨¨¨¨¨¨¨¨¨¨/¨¨¨¨\¨¨¨¨¨¨¨¨¨¨¨
¨¨¨¨¨¨¨¨¨¨¨¨/¨¨¨¨¨\¨¨¨¨¨¨¨¨¨¨/¨¨¨¨¨¨\¨¨¨¨¨¨¨¨¨¨
¨¨¨¨¨¨¨¨¨¨¨/¨¨¨¨¨¨¨\¨¨¨¨¨¨¨¨/¨¨¨¨¨¨¨¨\¨¨¨¨¨¨¨¨¨
DLLb¨::¨nonshared¨'Sharedsegment'¨¨nonshared¨::¨¨¨
¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
I join a demo code below. But this is rather an unperfect solution for I haven't found how to get rid of those limitations :
- It is not 100% fb since it will require a C++ dll -> I've been using ms visual c++ to set this one up
- The executables instances have to be linked to the same dll, not a copy - even identical - found in another place (unless of course I'm doing wrong)
And also, and it would be my first concern, how doing the job with 100% fb stuff ?
Example code of a 'dll shared segment' allowing data exchange between executables clones:
Code: Select all
="cpp file compile as dll"
Code: Select all
//vcppproj01.h
#Ifdef VCPPPROJ01_EXPORTS
#define VCPPPROJ01_API __declspec(dllexport)
#else
#define VCPPPROJ01_API __declspec(dllimport)
#endif
// Cette classe est exportée de vcppproj01.dll
class VCPPPROJ01_API Cvcppproj01 {
public:
Cvcppproj01(void);
// TODO : ajoutez ici vos méthodes.
};
extern VCPPPROJ01_API int nvcppproj01;
VCPPPROJ01_API int fnvcppproj01(void);
Code: Select all
// vcppproj01.cpp : définit le point d'entrée pour l'application DLL.
//
#include "stdafx.h"
#include "vcppproj01.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
#pragma data_seg(".sdata") // start of section - must initialize!
extern "C" __declspec (dllexport) int _sharedData = 10;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.sdata,rws")
extern "C" __declspec (dllexport) INT GetSharedData()
{
return _sharedData;
}
extern "C" __declspec (dllexport) INT SetSharedData(INT setData )
{
_sharedData = setData;
return _sharedData;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
Code: Select all
="bas file compile as exe"
Code: Select all
''Program able to share a variable between multiple instances
''Via a c++ dll embedding a shared data section
''
''Usage :
''compile to an exe, then launch the exe 2 times and more
''Load library with the 'shared data segment'
Dim As Any Ptr vcppLib = DyLibLoad( "vcppproj01" )
''Load the functions that accesses to the shared data
Dim _GetSharedData As Function () As Integer
_GetSharedData = DylibSymbol( vcppLib, "GetSharedData" )
Dim _SetSharedData As Function (ByVal As Integer) As Integer
_SetSharedData = DylibSymbol( vcppLib, "SetSharedData" )
''Some utility to get a random ID to identify the instance
Dim Shared As String currentID
currentID = ""
Dim Shared As Integer colorStamp
Declare Function ReturnCurrentID() As String
Declare Function ShowID() As Integer
''Variables
Dim As String _str
Dim As Integer _number
''=================================================================MAIN
''Initialize
Randomize Timer
Screen 0 : Cls
Locate 13,10 : ? "(long)Press [ESC] to leave"
ShowID()
''Interrogate the shareddata
Do
Locate 10,10 : ? "Content of shared data :" ;
? _GetSharedData()
Locate 12,10 : ? "Press [SPACE] to modify data"
If InKey = Chr(32) Then
Input "Enter a number to send in the shared pool"; _number
_SetSharedData(_number)
Cls
Locate 13,10 : ? "Keep pressing [ESC] to leave"
ShowID()
EndIf
Loop Until InKey = Chr(27)
''=====================================================================
Sleep : End 0
Function ReturnCurrentID() As String
If currentID = "" Then
Dim As String voyelTable(5)
Dim As String consonantTable (10)
Dim As String signTable(3)
''Feed all this people
For _index As Integer = 0 To 5
Read voyelTable(_index)
Next _index
For _index As Integer = 0 To 10
Read consonantTable(_index)
Next _index
For _index As Integer = 0 To 3
Read signTable(_index)
Next _index
For _i As Integer = 1 To 12
currentID &= voyelTable(Int(Rnd*6))& _
consonantTable(Int(Rnd*11))& _
IIf (_i Mod 4 = 0, signTable(Int(Rnd*3)), "")
Next _i
colorStamp = Int(Rnd*14)+1
EndIf
Return currentID
End Function 'STRING := ReturnCurrentID()
Function ShowID() As Integer
Dim As Integer _initialLine = CsrLin()
Dim As Integer _intitialColumn = Pos()
Locate 1, 55 : ? "<Instance ID>"
Color 11, 3
Locate 2, 55 : ? ReturnCurrentID()
Color , colorStamp
For _line As Integer = 1 To 25
Locate _line, 80 : ? Space(1);
Next _line
Color 7, 0
Locate _initialLine, _intitialColumn
End Function 'INTEGER := ShowID()
voyels:
Data "", "a", "e", "1", "0", "U"
consonants:
Data "", "Z", "b", "c", "d", "Y", "f", "g", "H", "X", "j"
signs:
Data "", "-", "_", "@"