Jump to content
Guest

_SharedVar (IPC) - Share variables between Autoit and C++/Autoit directly on memory

Recommended Posts

Guest

Hello,
In recent days I have researched about how to make shared variables

This code is designed to give the ability to:
[Autoit A <-in/out--> Autoit B]
[C++ <--in/out--> Autoit]
[C++ A <--in/out--> C++ B]

 

56de0885d9e76_example1.thumb.png.3ad2517

56de0efcd3e3f_example2.thumb.png.6fa9ca3

56de0f1fa789b_example3.thumb.png.fc87e09

56de0f34a7f5e_example4.thumb.png.74013a1

 

Key points:

  • Share variables between number of processes using the memory (ram). It does not share the information through file (like ini or something like that). it works on pure memory.
  •  Share variables between 1+ Autoit process(s) to to 1+ C++ process(s).
  •  Any process can be master.. but on different variables.. for example Process A can be master for variables X, Y, Z while Process B can be master for variables Q, R, T. (Not showed in the examples).  In C++ version these rules are more flexible.
  • arrays between Autoit and C++ transfer theoretically.
  • You can share as many variables you want.

 

Please note:
You can get race condition bug.
If you share some variable between processes, make sure that when Sub-system-A is changing variable X, Sub-system-B (that running in other process) will not use variable X for calculation..
In this case
you should design the code so only one sub-system will run.. for this you can create shared variable that for
each sub-system that will "say" that this system is run.. so for example Sub-system-B will run only if the variable "say" that Sub-system-A is not running.
I do not know if you understanding .. Probably not. It's hard to explain.

The important thing is - these functions are not designed to handle the "race condition". You need to make sure in your code area that race condition will not happen.
 


Example codes:

 

Spoiler

 

Autoit - Process A & Process B:
 

#include '_SharedVar.au3'
#include '_GUIConsole.au3'


; NOTE: For definitions read more in _SharedVar.au3




_GUIConsole_Create(Default,$COLOR_BLUE,$COLOR_WHITE,701,580)



_GUIConsole_Out('In which way you want to share the *info with the *target_process ?'&@CRLF& _
                'Enter 1 to share the *info using pointer to memory address (Recommended and default).'&@CRLF& _
                'Enter 0 to share the *info using pointer to a hidden GUI window.')
;


While 1
    _GUIConsole_Out('Your answer: ',0)
    $iMode = Number(_GUIConsole_In())
    Switch $iMode
        Case $SharedVar_PTR_Hidden_GUI_Mode,$SharedVar_PTR_MEM_ADDRESS_Mode
            ExitLoop
        Case Else
            _GUIConsole_Out('Your must enter 0 or 1.')
    EndSwitch
WEnd



_GUIConsole_Out(@CRLF&'Preparing for declaration...')



; SETP 1
_SharedVar_InitializeShare($iMode) ; Set the way of how the *Info will be shared.
Switch $iMode
    Case $SharedVar_PTR_Hidden_GUI_Mode
        _GUIConsole_Out('Pointer to hidden GUI (Pointer type 0): ',0)
    Case $SharedVar_PTR_MEM_ADDRESS_Mode
        _GUIConsole_Out('Pointer to memory address (Pointer type 1): ',0)
EndSwitch
_GUIConsole_Out($gg_sv_pPointer4vars)


_GUIConsole_Out(@CRLF&'This process ( This is the *target_process from the viewpoint of Process B):'&@CRLF& _
                '   PID: '&@AutoItPID &@CRLF& _
                '   Pointer for *info: '&$gg_sv_pPointer4vars &@CRLF& _
                '   Pointer type: '&$iMode,2)
;



_SharedVar_SetTargetProcess(0)
; NOTE 1: If you use 0 in this function, then before this you must first call to _SharedVar_InitializeShare !
; NOTE 2: If set to 0 then it will not set *target_process. It will just set this process..



;You first need to declare the variable normaly. then you give the normal variable to _SharedVar_DeclareVar.
;_SharedVar_DeclareVar will upgrade the variable to be shared variable.
;
;** NOTE: before you give the variable to _SharedVar_DeclareVar, first you must keep the following rules:
;A) The value of the variable will be unique identifier. the unique identifier must be only number. * not x.x(for example 0.5 or 1.2). only x (for example: 1)
;Example:: Correct: "$var = 1, $var2 = 2 ...". Wrong: "$var = 1, $var2 = 1 ...".
;   In this case $var2 can't have value 1 because it is the value of $var1.
;   $var2 can store any value except 1.
;   The variables must not contain values like 0.1,1.1 ... (x.*)
; B) The data type of the same variable will be EXACTLY the same in all processes.
;   Example::: Correct:: Inside "Process A": data type of $var is "char[20]". And Inside "Process B":
;   the data type of $var is "char[20]". Wrong:: Inside "Process A": data type of $var is "char[20]". And Inside "Process B":
;   the data type of $var is "char[19]".
; C) You will never change the variable normally. You do it only with  _sv_write(*)
; declare the variables
; D) The unique identifier of the variable will be the same in the other process.
;   Example::: Correct:: Inside "Process A": $var = 1. And Inside "Process B": $var = 1. Wrong:: Inside "Process A": $var = 1. And Inside "Process B": $var = 2.
; E) If the value of the variable stored in C++ process, make sure that no reallocation will occur!
;   If the value stored in Autoit process then it should be safe Because probably in autoit you don't
;   have option to paly with it enough to get reallocation.


_GUIConsole_Out('Declaring *shared_variable(s) ...')


$iValue1 = 1
$sValue2 = 2


; NOTE: You must first call to _SharedVar_SetTargetProcess or _SharedVar_SetNewTargetProcess before calling _SharedVar_DeclareVar
;       And enure that no error occurred

;                              vv Data type must be the same in the *target_process
_SharedVar_DeclareVar($iValue1,'int',10) ; Declare var1 so it will store integer value. And (optional) write the value 10
_SharedVar_DeclareVar($sValue2,'char[255]','Hello world!') ; Declare var2 so it will store string value. And (optional) write the value 'Hello world!'




_GUIConsole_Out(@CRLF&'Declared *shared_variable(s) (source values inside this process):' &@CRLF& _
                'iValue1 = '& _sv_read($iValue1) _ ; <- This is how you read the value
                &@CRLF&'sValue2 = '&_sv_read($sValue2) _ ; <- This is how you read the value
                ,2)


_GUIConsole_Out('Info: when the process from outside will try to connect to these *shared_variable(s), it will get this *info :'&@CRLF&@TAB& _
$gg_sv_sDeclaredVars&@CRLF&@TAB&'using the pointer '&$gg_sv_pPointer4vars& ' (Pointer type '&$iMode&')',3)



_GUIConsole_Out('Would you like to open Process B now? Select y/Y for yes, any key for no.')
_GUIConsole_Out('Your answer: ',0)
If StringLower(_GUIConsole_In()) = 'y' Then
    Local $ProcessB_Pid = ShellExecute(@ScriptDir&'\Example - [Autoit] Process B.exe',@AutoItPID&' '&$gg_sv_pPointer4vars&' '&$iMode,@ScriptDir)
    If Not $ProcessB_Pid Then _GUIConsole_Out('Failed to open the exe file. You need to open it manually.',2)
EndIf




_GUIConsole_Out(@CRLF&'What do you want to do now?'&@CRLF& _
'1 = Print iValue1 , 2 = Print sValue2 , 3 = change iValue1 , 4 = change sValue2 , 5 = Exit')
While 1
    Switch Number(_GUIConsole_In(1))
        Case 1
            _GUIConsole_Out(' -> The value of iValue1 is '&_sv_read($iValue1))
        Case 2
            _GUIConsole_Out(' -> The value of sValue2 is '&_sv_read($sValue2))

        Case 3
            _GUIConsole_Out(' -> Write the new value for iValue1 (must be int): ',0)
            $NewValue = Number(_GUIConsole_In(1))
            _sv_write($iValue1,$NewValue) ; <- This is how you write the value
            If Not @error Then
                _GUIConsole_Out(' -> The value changed to '&$NewValue&' .')
            Else
                _GUIConsole_Out(' -> Failed to change the value to '&$NewValue&' .')
            EndIf
        Case 4
            _GUIConsole_Out(' -> Write the new value for sValue2 (must be string char[255]): ',0)
            $NewValue = _GUIConsole_In(1)
            _sv_write($sValue2,$NewValue) ; <- This is how you write the value
            If Not @error Then
                _GUIConsole_Out(' -> The value changed to '&$NewValue&' .')
            Else
                _GUIConsole_Out(' -> Failed to change the value to '&$NewValue&' .')
            EndIf
        Case 5
            _GUIConsole_Out(' -> Are you sure you want to exit? (y = yes, n = no): ',0)
            If _GUIConsole_In(1) = 'y' Then
                Sleep(500)
                Exit
            EndIf
            _GUIConsole_Out('')
        Case Else
            _GUIConsole_Out(@CRLF&'Only 1,2,3,4,5 are valid.')
    EndSwitch

WEnd













#Region Debug
Func Exit1()
    Exit
EndFunc
#EndRegion

 

#include '_SharedVar.au3'
#include '_GUIConsole.au3'



; NOTE: For definitions read more in _SharedVar.au3



_GUIConsole_Create(Default,$COLOR_GREEN,$COLOR_WHITE,701,580)
_GUIConsole_Out('The PID of this process = '&@AutoItPID,2)



Local $ProcessA_Pid,$ProcessA_Pointer,$ProcessA_PointerType




If @Compiled And $CmdLine[0] = 3 Then
    $ProcessA_Pid = $CmdLine[1]
    $ProcessA_Pointer = $CmdLine[2]
    $ProcessA_PointerType = Number($CmdLine[3])
    _GUIConsole_Out('(Got the necessary information for the connection to the *shared_variable(s) in Process A from the cmdline parameters) ',0)
Else

    _GUIConsole_Out('Write the *target_process information:')
    _GUIConsole_Out('   Enter the PID of Process A: ',0)
    $ProcessA_Pid = Number(_GUIConsole_In())
    _GUIConsole_Out('   Enter the pointer for *info of Process A: ',0)
    $ProcessA_Pointer = Number(_GUIConsole_In())
    _GUIConsole_Out('   Enter the pointer type: ',0)
    $ProcessA_PointerType = Number(_GUIConsole_In())
EndIf



_GUIConsole_Out(@CRLF&@CRLF&'*target_process (Process A):'&@CRLF& _
                '   PID of Process A: '&$ProcessA_Pid &@CRLF& _
                '   Pointer for *info of Process A: '&$ProcessA_Pointer &@CRLF& _
                '   Pointer type of Process A: '&$ProcessA_PointerType,2)
;


; Set *target_process to be Process A
_SharedVar_SetNewTargetProcess($ProcessA_Pid,$ProcessA_Pointer,$ProcessA_PointerType)



;You first need to declare the variable normaly. then you give the normal variable to _SharedVar_DeclareVar.
;_SharedVar_DeclareVar will upgrade the variable to be shared variable.
;
;** NOTE: before you give the variable to _SharedVar_DeclareVar, first you must keep the following rules:
;A) The value of the variable will be unique identifier. the unique identifier must be only number. * not x.x(for example 0.5 or 1.2). only x (for example: 1)
;Example:: Correct: "$var = 1, $var2 = 2 ...". Wrong: "$var = 1, $var2 = 1 ...".
;   In this case $var2 can't have value 1 because it is the value of $var1.
;   $var2 can store any value except 1.
;   The variables must not contain values like 0.1,1.1 ... (x.*)
; B) The data type of the same variable will be exactly the same in all processes.
;   Example::: Correct:: Inside "Process A": data type of $var is "char[20]". And Inside "Process B":
;   the data type of $var is "char[20]". Wrong:: Inside "Process A": data type of $var is "char[20]". And Inside "Process B":
;   the data type of $var is "char[19]".
; C) You will never change the variable normally. You do it only with  _sv_write(*)
; declare the variables
; D) The unique identifier of the variable will be the same in the other process.
;   Example::: Correct:: Inside "Process A": $var = 1. And Inside "Process B": $var = 1. Wrong:: Inside "Process A": $var = 1. And Inside "Process B": $var = 2.
; E) If the value of the variable stored in C++ process, make sure that no reallocation will occur!
;   If the value stored in Autoit process then it should be safe Because probably in autoit you don't
;   have option to paly with it enough to get reallocation.


_GUIConsole_Out('Declaring variables (Make connection to the *shared_variable(s) in the "Process A") ...',2)

$iValue1 = 1
$sValue2 = 2


; NOTE: You must first call to _SharedVar_SetTargetProcess or _SharedVar_SetNewTargetProcess before calling _SharedVar_DeclareVar
;       And enure that no error occurred


_SharedVar_DeclareVar($iValue1,'int') ; Declare iValue1 -> Connect iValue1 (inside Process B) to iValue1 (inside Process A)
_SharedVar_DeclareVar($sValue2,'char[255]') ; Declare sValue2 -> Connect sValue2 (inside Process B) to sValue2 (inside Process A)
; NOTE 1: Because we set *target_process to be not this process, this functions make "only" connection to the *shared_variable that stored in *target_process.
;         Because of this you can't set value in this function (it will get the value from the *target_process)

If @error Then
    _GUIConsole_Out('!!! An error occurred in declaration of variables. The error occurred in line '&@error&' . !!!')
    Sleep(10000)
    Exit
EndIf


; Print the shared variables
_GUIConsole_Out('Declared *shared_variable(s) (Stored in Process A):' &@CRLF& _
                'iValue1 = '& _sv_read($iValue1) _ ; <- This is how you read the value
                &@CRLF&'sValue2 = '&_sv_read($sValue2) _ ; <- This is how you read the value
                ,2)



Sleep(500)


_GUIConsole_Out('What do you want to do now?'&@CRLF& _
'1 = Print iValue1 , 2 = Print sValue2 , 3 = change iValue1 , 4 = change sValue2 , 5 = Exit')
While 1
    Switch Number(_GUIConsole_In(1))
        Case 1
            _GUIConsole_Out(' -> The value of iValue1 is '&_sv_read($iValue1))
        Case 2
            _GUIConsole_Out(' -> The value of sValue2 is '&_sv_read($sValue2))

        Case 3
            _GUIConsole_Out(' -> Write the new value for iValue1 (must be int): ',0)
            $NewValue = Number(_GUIConsole_In(1))
            _sv_write($iValue1,$NewValue) ; <- This is how you write the value
            If Not @error Then
                _GUIConsole_Out(' -> The value changed to '&$NewValue&' .')
            Else
                _GUIConsole_Out(' -> Failed to change the value to '&$NewValue&' .')
            EndIf
        Case 4
            _GUIConsole_Out(' -> Write the new value for sValue2 (must be string char[255]): ',0)
            $NewValue = _GUIConsole_In(1)
            _sv_write($sValue2,$NewValue) ; <- This is how you write the value
            If Not @error Then
                _GUIConsole_Out(' -> The value changed to '&$NewValue&' .')
            Else
                _GUIConsole_Out(' -> Failed to change the value to '&$NewValue&' .')
            EndIf
        Case 5
            _GUIConsole_Out(' -> Are you sure you want to exit? (y = yes, n = no): ',0)
            If _GUIConsole_In(1) = 'y' Then
                Sleep(500)
                Exit
            EndIf
            _GUIConsole_Out('')
        Case Else
            _GUIConsole_Out(@CRLF&'Only 1,2,3,4,5 are valid.')
    EndSwitch

WEnd

 

C++ - Process A & Process B:
 

/// Example: Process A
#include <iostream>    // using IO functions
#include <string>      // using string
#include <windows.h>
#include <vector>
//#include <psapi.h>

#include <sstream> //for std::stringstream
#include "_SharedVar.h"

/// NOTE: For definitions read more in SharedVar.h

using namespace std; 

int main(){
    cout <<
    "Preparing for declaration..."
    << endl;

    /// Load SharedVar functions
    Class_SharedVar SharedVar;

    /// Initialize (Must call it once before using the functions)
    SharedVar.initialize();


    cout << endl <<
    "This process (This is the *target_process from the viewpoint of Process B):" << endl <<
    "   PID: " << GetCurrentProcessId() << endl <<
    /// Only type 1 supported in c++
    "   Pointer for *info (Pointer type 1): " + SharedVar.spSharedVars
    << endl << endl;


    cout <<
    "Step 1: Declaring variables ... (allocating memory and declaring the varibles)"
    << endl;
    /// In Autoit you make the shared_variable with _SharedVar_DeclareVar.
    /// In C++ (STEP 1) you declare the variable normally (** EXACTLY the same data type )

/// data type                value                                                        data type   value
       int   iValue1    =      10       ; /// Equivalent to "_SharedVar_DeclareVar($iValue1, 'int'   ,  10 )"
      char sValue1[255] = "Hello world!"; /// Equivalent to "_SharedVar_DeclareVar($sValue1,'char[255]','Hello world!')"

    /// Then (STEP 2) you share the variable with .share
    cout <<
    "Step 2: Sharing variables ..."
    << endl << endl ;
    ///           (id)                                                    (id)
    SharedVar.share(1,&iValue1); /// Equivalent to "_SharedVar_DeclareVar($iValue1,'int',10)"
    SharedVar.share(2,&sValue1); /// Equivalent to "_SharedVar_DeclareVar($sValue1,'char[255]','Hello world!')"

    /// ^ This is also called *parallel_variable from the view point of process b.


    cout <<
    "Declared shared variables:" << endl <<
    "iValue1 = " << iValue1 << endl <<
    "sValue1 = " << sValue1 << endl << endl;

    cout <<
    "Info: when the process from outside will try to connect to these variables," << endl <<
    "it will get this string: " << SharedVar.cSharedVars << endl <<
    "using the pointer " << SharedVar.spSharedVars << " (Pointer type 1)" << endl << endl;
    //(Pointer type 1)


    int iUserChoise = 0; char cInput;
    cout <<
    "What do you want to do now?" << endl <<
    "1 = Print iValue1 , 2 = Print sValue1 , 3 = change iValue1 , 4 = change sValue1 5 = Exit" << endl;

    while (1) {
        cin >> iUserChoise;
        switch (iUserChoise){
        case 1:
            cout << "^ --> The value of iValue1 is " << iValue1 << endl;
            break;
        case 2:
            cout << "^ --> The value of sValue1 is " << sValue1 << endl;
            break;
        case 3:
            cout << "^ --> Write the new value for iValue1 (must be int):" << endl;
            cin >> iValue1;
            cout << "^ --> The value changed to: " << iValue1 << endl;
            break;
        case 4:
            cout << "^ --> Write the new value for sValue1:" << endl;
            cin >> sValue1; /// Equivalent to "L_iVar2 = <Your new value>"
            cout << "^ --> The value changed to: " << sValue1 << endl;
            break;

        case 5:
            return 1;

        default:
            cout << "Only 1,2,3,4,5 are valid." << endl;
        }
    }




}

#include <iostream>    // using IO functions
#include <string>      // using string
#include <windows.h>
#include <vector>
//#include <psapi.h>

#include <sstream> //for std::stringstream
#include "_SharedVar.h"


/// NOTE: For definitions read more in SharedVar.h

using namespace std;

int main(){

    int iTmp;int iTargetProcessPid; int pTargetProcessPointer = 0; string sTmp1;



    /// Load SharedVar functions
    Class_SharedVar SharedVar;

    /// Initialize (Must call it once before using the functions)
    SharedVar.initialize();

    cout << "Write the *target_process information:" << endl;
    cout << "   Enter the PID of Process A: "; cin >> iTargetProcessPid;
    cout << "   Enter the pointer for *info of Process A: "; cin >> sTmp1;
    pTargetProcessPointer = SharedVar.StrPtr2IntPtr(&sTmp1);




    /// Add new target process and set it to be the active one
    iTmp = SharedVar.SetNewTargetProcess(iTargetProcessPid,pTargetProcessPointer);
    //iTmp = SharedVar.SetNewTargetProcess(8676,0x00A38968);
    /// NOTE 1: If you are going to use .CreateLinker & .Update then you must first set
    ///         the target process by .SetNewTargetProcess or .SetTargetProcess
    /// NOTE 2: If error then the return is (int)<0. If not error then the return is 1
    if (iTmp < 0) {cout << "Problem in setting and adding the process."; return -1;}


    /// Declare the *copy_variable(s)
    /// NOTE 1: The data type must be exactly the same!
    int iValue1 = 0;
    char sValue2[255] = "";
    /// In this case - because the variable intended to be copy to its parallel variable,
    /// you should assign to it empty value. It will get the value later from the *parallel_variable


    /// Create *linker(s) for these^ variables to their *parallel_variable(s) that stored
    /// in the *target_process (Defined by SetNewTargetProcess or SetTargetProcess).
    C_oVarLinker iValue1_linker = SharedVar.CreateLinker(1,&iValue1,sizeof(iValue1));
    C_oVarLinker sValue2_linker = SharedVar.CreateLinker(2,&sValue2,sizeof(sValue2));
    /// NOTE 1: You must set the *target_process and ensure that there is no error in
    ///          this operation. make sure that SetNewTargetProcess or SetTargetProcess
    ///          did not return error before using .CreateLinker().
    /// NOTE 2: If error then *linker.pTargetPtr is equal to -1
    if (iValue1_linker.pTargetPtr == -1) {cout << "Problem in creating linker to iValue1."; return -2;}


    /// Update the *copy_variable(s) to the values of their *parallel_variable(s) using the *linker(s)
    SharedVar.UpdateIn(&iValue1_linker); /* Read the value of iValue1 (*parallel_variable) using iValue1_linker (*linker)
    --> Save the returned value in iValue1 (*copy_variable) using iValue1_linker (*linker)                                                 */
    SharedVar.UpdateIn(&sValue2_linker); /* Read the value of sValue2 (*parallel_variable) using sValue2_linker (*linker)
    --> Save the returned value in sValue2 (*copy_variable) using sValue2_linker (*linker)                                                 */

    /// Print the *copy_variable(s)
    cout << endl <<
    "Declared shared variables:" << endl <<
    "iValue1 = " << iValue1 << endl <<
    "sValue2 = " << sValue2 << endl << endl;


    int iUserChoise = 0; char cInput;
    cout <<
    "What do you want to do now?" << endl <<
    "1 = Print iValue1 , 2 = Print sValue2 , 3 = change iValue1 , 4 = change sValue2 5 = Exit" << endl;

    while (1) {
        cin >> iUserChoise;
        switch (iUserChoise){
        case 1:
            SharedVar.UpdateIn(&iValue1_linker); /// Update the value of iValue1 (*copy_variable) to the new value
                                                 /// of iValue1 (*parallel_variable) using iValue1_linker (*linker)

            cout << "^ --> The value of iValue1 is " << iValue1 << endl; /// Print the value of iValue1 (*copy_variable)
            break;
        case 2:
            SharedVar.UpdateIn(&sValue2_linker); /// Update the value of sValue2 (*copy_variable) to the new value
                                                 /// of sValue2 (*parallel_variable) using sValue2_linker (*linker)

            cout << "^ --> The value of sValue2 is " << sValue2 << endl; /// Print the value of sValue2 (*copy_variable)
            break;
        case 3:
            cout << "^ --> Write the new value for iValue1 (must be int):" << endl;
            cin >> iValue1;                       /// Change the value of iValue1 (*copy_variable)

            SharedVar.UpdateOut(&iValue1_linker); /// Update the value of iValue1 (*parallel_variable) to the new value
                                                  /// of iValue1 (*copy_variable) using iValue1_linker (*linker)

            cout << "^ --> The value changed to: " << iValue1 << endl; /// Print the value of iValue1 (*copy_variable)
            break;
        case 4:
            cout << "^ --> Write the new value for sValue2:" << endl;
            cin >> sValue2;                       /// Change the value of sValue2 (*copy_variable)

            SharedVar.UpdateOut(&sValue2_linker); /// Update the value of sValue2 (*parallel_variable) to the new value
                                                  /// of sValue2 (*copy_variable) using sValue2_linker (*linker)
            cout << "^ --> The value changed to: " << sValue2 << endl; /// Print the value of sValue2 (*copy_variable)
            break;

        case 5:
            return 1;

        default:
            cout << "Only 1,2,3,4,5 are valid." << endl;

        }


    }


}


 

Functions:
Autoit version (v2.3):
_SharedVar_InitializeShare - Initialize/set the way of how the variables that stored inside this process will be shared with other processes.
_SharedVar_SetTargetProcess - Set *target_process (not new process)
_SharedVar_SetNewTargetProcess - Set and add the new *target_process of where to connect the variables during the declaration.
_SharedVar_DeclareVar - Declare the *shared_variable
_sv_write - Write Value in the *shared_variable
_sv_read - Read the *shared_variable
_sv_readlast - Get the last readed value from the *shared_variable.
_SharedVar_CloseProcess - Close the memory handle of the process if memory handle create before.

C++ version (v1.0):
.initialize - initialize for the functions. You must call it once before using any functions in this library!
.share - Share the variable with the other process
.CreateLinker - Create *linker for the variable, return *linker
.UpdateIn(*linker) - Update the *copy_variable to the value of *parallel_variable (Equivalent to _sv_read(*))
.UpdateOut(*linker) - Update the *parallel_variable to the value of *copy_variable (Equivalent to _sv_write(*))
.SetNewTargetProcess - Set and add the new *target_process of where to connect the variables...
.SetTargetProcess - Set *target_process that was added before (not new process)
.StrPtr2IntPtr - Convert [Pointer as string] to [Pointer as int]

Download:

Latest Version (C++ version  and Autoit version)

https://github.com/GilEli1/-Autoit-C-Shared-Vars/releases/tag/1

 

_SharedVar v2.1.rar

* _SharedVar_ReadVar changed to _sv_read
* _SharedVar_WriteValue changed to _sv_write
* Much better example thanks to my _GUIConsole
* Removed old unused code from v1
* Removed unnecessary errors checks
* Fixed bug in _SharedVar_SetDeclarationsInProcess

_SharedVar v2.rar
_SharedVar v1.rar

 

Enjoy ! :)

 

 

Edited by Guest

Share this post


Link to post
Share on other sites
Guest
11 minutes ago, argumentum said:
HotKeySet('{ESC}','Exit1')

won't work for both :( , other than that, nice :) 
What would the max string length be to use ?

I know it does not work.
But I spend time on the hard part and I have no time for small things..

About your question -
I did not mention it: If the shared variable may at some point store string value that is bigger then the string that was assigned during the first declaration then you must  to declare the variable bit differently:

In _SharedVar_DeclareVar, in parameter $DataType you need to write the DataType manually.
Try 'char[255]'

Then when you write another string, it will be fine as long as the string smaller then 255 characters.

I have no power today to check it out more. It should work

Share this post


Link to post
Share on other sites
Guest
13 minutes ago, Xandy said:

Hi I just wanted to chime in that I am very interested in this idea and / or any spin off works.  Thank you very much for your pursuit of this goal.

Good luck :)

Thanks.
I found a great breakthrough


I will continue to run on it tests on it in the following days when I have free time.
If I see that it works stable enough, I'm probably going to do  separate version of this function which will work much more effectively for Autoit and for the user.

Share this post


Link to post
Share on other sites
Guest

Updated again.
I do not like to say this, but I have to:
likes are not enough.

I need comments.

I will now start working on version of this functions for C++ ( _SharedVar.cpp )

Edited by Guest

Share this post


Link to post
Share on other sites

Isn't this just a proof of concept and not something that is "production" viable?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Guest
5 hours ago, guinness said:

Isn't this just a proof of concept and not something that is "production" viable?

I did not understand the question.
Can you explain more the question?


What do you mean by saying  ' "production" viable' ?
Edit: I think that I understand but I hope I understand it wrong

Edited by Guest

Share this post


Link to post
Share on other sites

To me production viable means, can it be relied on?  I've been very busy myself working on a multiclient game server and I might have a need of this to speed up sub processes performed by compiled scripts or even C++.  I've been busy but is there something I could help you with?  Maybe you could bring me up to speed with a teamviewer session or workflow videos.  But then that is time you're not doing this and like I said I am busy but you can let me know if that is something you'll want to do.

Edited by Xandy

Share this post


Link to post
Share on other sites
Guest

Thanks for your suggestion. :) At the moment I do not need help.

Edited by Guest

Share this post


Link to post
Share on other sites

Thanks for sharing! :thumbsup:

On 20/2/2016 at 5:47 AM, gil900 said:

I do not like to say this, but I have to:
likes are not enough.
I need comments.

Why? What is there to say really? :blink:

It either works or it doesn't, and people either like it or they don't.

To me, it is a thought provoking niche project.

I can see where it can come in handy due to speed and permissions issues over sharing a Registry entry or something like an INI file, but I'm not sure how many exactly have an immediate need for this, or are just like me, storing it away for that day? To make further comment now, you really need to be using it here and now.

And further to all that, I guess it is only useful where you are the author of all the programs that will be sharing the variable(s) ... or have access to the source codes of all ... so that limits things even further.

Don't get me wrong though, I'm glad for your hard work and that you shared this. :D

P.S. In all reality, you are lucky to get a Like, as many offerings here don't even get that or a 'Thank You' despite large numbers of downloads, etc ... and comments are even rarer unless a bug is found or understanding is difficult. :'(

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
Guest

Thank you,
What I said about the likes..., on second thought I should not say this ..
My approach is changing. I do what I do for fun. I probably would continue to work on this project anyway..Probably in a week from now, I'll  finish to create c++  Version so c++ exe will able to share variables with autoit (using this implemented communication standard)it means that in theory you can for example write all the gui stuff in Autoit and the other in c and it will act like one program. This is my goal and it is fun to build the base for this.

Edited by Guest

Share this post


Link to post
Share on other sites
Guest

So I had some free time today and I made small progress:
 

Spoiler

56d62cacac8b0_ccodeexample1.thumb.png.cd56d62cbca90f3_ccodeexample2.thumb.png.ca

 

Edited by Guest

Share this post


Link to post
Share on other sites
Guest

Updated: C++ Version released. Autoit version improved

Edited by Guest

Share this post


Link to post
Share on other sites
Guest

Updated: added more documentation

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...